@matrix sizeof doesn't return the size of an array you fucking Clet
Follow

@rgk Oh, shit right. Compiler is telling me too :lul:

warning: division 'sizeof (int *) / sizeof (int)' does not compute the number of array elements [-Wsizeof-pointer-div]

· · Web · 1 · 0 · 0
@matrix sizeof just returns the size in bytes for type. It doesn't even evaluate the expression (unless VLA IIRC, don't quote me.)
It just returns the size of the type of the expression.

uint32_t[10] is a type, uint32_t[11] is a different type. Hence why compiler knows this and can tell you this.

If you give it a a pointer, be it from malloc, cast, or you passed an array through function arg which is a pointer, it will lose that information (coz how the fuck would it know what you passed to a function at runtime)

so all it has to work with is size, in bytes, of pointer on your machine.

You got 2 coz you are on 64bit machine with 8byte pointers which you divide by sizeof int which is (usually) 4 bytes.

/sprg
Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.