Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

sizeof

Name: Anonymous 2009-04-26 9:56

I have a function that relies on the sizeof statement to get the size of a constant array of unsigned bytes. Everytime I use the function the sizeof statement returns 4 regardless of the size of my array.

Here's the code that doesn't seem to work. The array argument is defined as a const u8 array[].

u8  c;
   
for(c = 0;c <= sizeof(array);++c){
    //do something here
}

Name: Anonymous 2009-04-26 17:49

An array's size is only available to sizeof in the direct scope where it is allocated on the stack.  The rest of the time it's just a pointer.   If you're stuck with sepples, then use std::vector<uint8_t>, otherwise get a language which has arrays rather than pointers with syntactic sugar.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List