Seymour J Metz wrote:

The difference is that sizeof is parsed as an operator.
Sometimes programs have parameterized declarations and the compiler must 
generate code to calculate sizeof.


--
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3
This is true - for C99 variable length arrays.   That was made an optional
feature of the latest standards, because it turns out to not be the best
idea.   Hopefully it will go away completely in the future.

The basic problem is the one of "catching" an out-of-memory situation,
C doesn't have any recourse in this case except to blow-up with an out-of-stack
(which generally causes a SIGSEGV on many platforms, an ABEND 978 in the
Dignus runtime.)   Whereas, a program can easily malloc() memory and
check for NULL and "do something" if there isn't sufficient memory.
(You _can_ set up an alternate signal stack and catch these issues, but
you can't continue the program's execution from them.)

C variable arrays were touted as a portable way to accomplish what
the non-portable alloca() function does in many implementations.   But,
the common alloca() will return NULL if there is no space... so, it's probably
a better approach.

C variable-length arrays are the only time sizeof() isn't a compile-time constant.

   - Dave Rivers -


--
[email protected]                        Work: (919) 676-0847
Get your mainframe programming tools at http://www.dignus.com

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to