sunnypalsingh
September 30th, 2005, 11:51 AM
Why can't we increment the value of i in sizeof like this:-
sizeof(i++)
sizeof(i++)
|
Click to See Complete Forum and Search --> : incrementing value in sizeof sunnypalsingh September 30th, 2005, 11:51 AM Why can't we increment the value of i in sizeof like this:- sizeof(i++) Paul McKenzie September 30th, 2005, 12:01 PM Why can't we increment the value of i in sizeof like this:- sizeof(i++)The sizeof() is a compile-time constant value depending on the argument. The argument to sizeof() must be a known type at compile time. The "i++" is not a type, it's an executable statement. Regards, Paul McKenzie SuperKoko September 30th, 2005, 12:05 PM This expression is valid (and returns the size of the return value of the expression i++), but it does not increment i. In fact, most expressions can be used with sizeof operator, but sizeof operator never evaluates the expression! -1- The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is not evaluated, or a parenthesized type-id. The sizeof operator shall not be applied to an expression that has function or incomplete type, or to an enumeration type before all its enumerators have been declared, or to the parenthesized name of such types, or to an lvalue that designates a bit-field. sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1; the result of sizeof applied to any other fundamental type (basic.fundamental) is implementation-defined. [Note: in particular, sizeof(bool) and sizeof(wchar_t) are implementation-defined.* sunnypalsingh September 30th, 2005, 12:25 PM Thanx a lot sunnypalsingh October 18th, 2005, 09:19 AM The sizeof() is a compile-time constant value depending on the argument. The argument to sizeof() must be a known type at compile time. The "i++" is not a type, it's an executable statement. Regards, Paul McKenzie According to the C99 standard..isn't this statement becomes wrong.....Since C99 introduced VLAs (variable length arrays) so the sizeof operator had to be modified to support VLAs. SuperKoko October 18th, 2005, 09:26 AM According to the C99 standard..isn't this statement becomes wrong.....Since C99 introduced VLAs (variable length arrays) so the sizeof operator had to be modified to support VLAs. // EDIT : What follows is the original post, which is false! No, variable length arrays are pointers in C99. That is, sizeof(VLA)==sizeof(Type *)==4 for a 32 bits compiler! sunnypalsingh October 18th, 2005, 09:31 AM okie.....got it SuperKoko October 18th, 2005, 09:32 AM According to the C99 standard..isn't this statement becomes wrong.....Since C99 introduced VLAs (variable length arrays) so the sizeof operator had to be modified to support VLAs. Sorry, i made an error: That code: #include <stdio.h> int main() { unsigned n; scanf("%u",&n); int VLA[n]; printf("%u",sizeof(VLA)); } Outputs 4*the_number_entered! So, VLA are really some different thing! sunnypalsingh October 18th, 2005, 09:37 AM Sorry, i made an error: That code: #include <stdio.h> int main() { unsigned n; scanf("%u",&n); int VLA[n]; printf("%u",sizeof(VLA)); } Outputs 4*the_number_entered! So, VLA are really some different thing! You know what...i am actually feeling great.... codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |