:: Re: [DNG] simple-netaid from scratc…
Top Pagina
Delete this message
Reply to this message
Auteur: s
Datum:  
Aan: dng
Onderwerp: Re: [DNG] simple-netaid from scratch

On Mon, 10 Jun 2019 17:58:35 +0200
Didier Kryn <kryn@???> wrote:

> Le 10/06/2019 à 16:01, s@po a écrit :
> > On Mon, 10 Jun 2019 13:34:54 +0100 (BST)
> > Jim Jackson <jj@???> wrote:
> >
> >> sizeof() is calculated by the compiler, not at run time. The code
> >> generated would be the same.
> > Hello Jim,
> > Indeed it his, my point was only a observation, that if size is fixed, no need to calculate it at compile time, the preprocessor can solve that with a macro..
> > The code generated will be indeed the same.
> > Only was a observation ;)
> >
> \begin{pedantic}
>     The size used by the layout of the data (sizeof()) has not the same
> meaning as the number of elements. AFAIK, the C language does not
> specify (at least not completely) the data layout and leaves it to the
> implementation.
>     All modern hardware lay out data as bit octets and compilers use
> one octet of bits to represent an ASCII character (note 7 would suffice
> for ASCII). All compilers layout strings in contiguous successive octets.
>     Therefore there is little chance that the confusion between size
> and number of elements be harmfull. Yet there is a subtle difference :~)
> \end{pedantic}
>


Indeed,
One harmfull situation is when you pass an array[n] to a function has an argument, for example..
Usign 'sizeof' inside, will return the size of the pointer and not the size of elements on the array..

unsigned char funtion test( unsigned char *array ){

        /* This will not return the size of array,
        but instead, the size of the Pointer..,
        because at compile time, compiler doesn't know what size array[n] will have */


    return sizeof( array )
}


Regards,

--
tux
s@po <tuxd3v@???>