Advertisement

sizeof(*data) returns 1?

Started by August 22, 2000 01:37 AM
12 comments, last by gimp 24 years, 4 months ago
strlen() also just looks for the ''\0'' chances are good that it''s nothing more than
    size_t strlen(char *s) {  size_t len = 0;  while(*s++) len++;  return len;}    


though there is a rep ???? assembly memonic that it may use. Regardless, the next binary ''\0'' may be a long way off, except of course, for every single time you or your testers run it.

quote:
Nope, it's computed at runtime, but *array just points to the first element of an array, whose size the function returns.


sizeof is compiler time, not runtime. Try this program:

        template<int N>class Test{};int main(int argc, char* argv[]){	Test<sizeof(int)> test;	return 0;}        


A template parameter needs to be know at compile time so that the correct template can be instantiated. If sizeof was a runtime function, this program wouldn't compile.

Edited by - Wilka on August 23, 2000 1:36:25 PM
Advertisement
Outch, perhaps I was too tired when I wrote about strlen()...
It would only add a \0 if there already had been one
Yesh, sizeof(ConfigLoaderMessageString) - 1 is right.

-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Thnaks guys I ended up taking Kylotan''s advice. I just lie to strlen. I guess this on confused me as I''ve been doing a load of sockets coding recently and getting the sizes back from structs etc...
Chris Brodie

This topic is closed to new replies.

Advertisement