|
-
September 30th, 2005, 11:51 AM
#1
incrementing value in sizeof
Why can't we increment the value of i in sizeof like this:-
Appreciate others by rating good posts
"Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett
-
September 30th, 2005, 12:01 PM
#2
Re: incrementing value in sizeof
 Originally Posted by sunnypalsingh
Why can't we increment the value of i in sizeof like this:-
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
-
September 30th, 2005, 12:05 PM
#3
Re: incrementing value in sizeof
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.*
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
September 30th, 2005, 12:25 PM
#4
Re: incrementing value in sizeof
Appreciate others by rating good posts
"Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett
-
October 18th, 2005, 09:19 AM
#5
Re: incrementing value in sizeof
 Originally Posted by Paul McKenzie
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.
Appreciate others by rating good posts
"Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett
-
October 18th, 2005, 09:26 AM
#6
Re: incrementing value in sizeof
 Originally Posted by sunnypalsingh
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!
Last edited by SuperKoko; October 18th, 2005 at 09:38 AM.
Reason: What i said is false
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
October 18th, 2005, 09:31 AM
#7
Re: incrementing value in sizeof
Appreciate others by rating good posts
"Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett
-
October 18th, 2005, 09:32 AM
#8
Re: incrementing value in sizeof
 Originally Posted by sunnypalsingh
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:
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!
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
October 18th, 2005, 09:37 AM
#9
Re: incrementing value in sizeof
 Originally Posted by SuperKoko
Sorry, i made an error:
That code:
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....
Appreciate others by rating good posts
"Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|