D
deepak
Hi,
Why an increment like sizeof(i++) is not incrementing value of i?
Thanks,
Deepak
Why an increment like sizeof(i++) is not incrementing value of i?
Thanks,
Deepak
Why an increment like sizeof(i++) is not incrementing value of i?
Why an increment like sizeof(i++) is not incrementing value of i?
deepak said:Hi,
Why an increment like sizeof(i++) is not incrementing value of i?
Also, consider that evaluating the expression could result in UB:
static int *pt = NULL;
...
pt = realloc(pt,newsize*sizeof(*pt));
pete said:VLA's are a needless complication of the language.
pete said:VLA's are a needless complication of the language.
On Tue, 04 Aug 2009 13:39:45 GMT James Kuyper
| If you're asking why the standard says this, the reason is that the
| intended use for sizeof was one for which it would, more often than not,
| be inconvenient for it to evaluate the expression. All that sizeof needs
| to know is the type of the expression that it operates on. Except when
| the argument is a VLA (which is why VLAs are an exception), that size
| can be determined at compile time and used wherever an integer constant
| expression might be used.
It should only need to evaluate the expression that determines the VLA size.
If the expression given to sizeof is more complex and the VLA and its size
is just a part, does the whole thing get evaluated? If the expression has
side effects like an increment, and the same VLA is used many times, does
this always increment each time? IWSTM that once the size is determined for
a VLA, such as entry to a function or block, then all references to the VLA
size should just extract that predetermined value.
| If you're asking why the standard says this, the reason is that the
| intended use for sizeof was one for which it would, more often than not,
| be inconvenient for it to evaluate the expression. All that sizeof needs
| to know is the type of the expression that it operates on. Except when
| the argument is a VLA (which is why VLAs are an exception), that size
| can be determined at compile time and used wherever an integer constant
| expression might be used.
It should only need to evaluate the expression that determines the VLA size.
If the expression given to sizeof is more complex and the VLA and its size
is just a part, does the whole thing get evaluated? If the expression has
side effects like an increment, and the same VLA is used many times, does
this always increment each time? IWSTM that once the size is determined for
a VLA, such as entry to a function or block, then all references to the VLA
size should just extract that predetermined value.
| If you're asking why the standard says this, the reason is that the
| intended use for sizeof was one for which it would, more often than not,
| be inconvenient for it to evaluate the expression. All that sizeof needs
| to know is the type of the expression that it operates on. Except when
| the argument is a VLA (which is why VLAs are an exception), that size
| can be determined at compile time and used wherever an integer constant
| expression might be used.
It should only need to evaluate the expression that determines the VLA size.
If the expression given to sizeof is more complex and the VLA and its size
is just a part, does the whole thing get evaluated?
If the expression has
side effects like an increment, and the same VLA is used many times, does
this always increment each time? IWSTM that once the size is determined for
a VLA, such as entry to a function or block, then all references to the VLA
size should just extract that predetermined value.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.