I was just wondering why, when I use the sizeof() function on a function name, it says the size is only one byte.
I was just wondering why, when I use the sizeof() function on a function name, it says the size is only one byte.
You can't simply get the size of your function by doing that. I'm not sure what's but I'm guessing it's giving you the size for the location where the function's address is being stored which should be 4 bytes.
Try not.
Do or do not.
There is no try.
- Master Yoda
hmmm... my compiler says:
Code:Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland junk1.c 8: sizeof may not be applied to a function in function main *** 1 errors in Compile ***
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
MSVC++ returned 4 bytes when I passed in main(). Behavior must be undefined heheh.
Try not.
Do or do not.
There is no try.
- Master Yoda
>>MSVC++ returned 4 bytes when I passed in main().
Good old Microsoft..!
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Well it should give you that. Think about it: sizeof( main )Originally posted by Hammer
>>MSVC++ returned 4 bytes when I passed in main().
Good old Microsoft..!
What exactly is the name of a function when used by itself? It's a pointer to that function. Thus, you could end up with the size of a pointer, which in any 32bit OS, is always 4 bytes.
Quzah.
Hope is the first step on the road to disappointment.
>>Well it should give you that.
No, it shouldn't. And thats already been proved by the fact the first three posters got three different results.
WG14/N869 Committee Draft — January 18, 1999 81
6.5.3.4 The sizeof operator
Constraints
1 The sizeof operator shall not be applied to an expression that has function type or an
incomplete type, to the parenthesized name of such a type, or to an expression that
designates a bit-field member.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
sizeof ((*funcptr)()) is ok
size of (func) isnt
hello, internet!
I didn't mean literally. I meant if you looked at it as to what it was applied to logicly. It was applied to the name of a function. Logicly then, since the name of a function itself, is a pointer to the function, it should give you the size of a function pointer.Originally posted by Hammer
>>Well it should give you that.
No, it shouldn't. And thats already been proved by the fact the first three posters got three different results.
Thus, logicly, it should give you 4 on a 32bit compiler/OS.
Quzah.
Hope is the first step on the road to disappointment.