Re: Another sizeof question



In article <pan.2007.09.19.10.22.54.771614@xxxxxxxxx>,
Army1987 <army1987@xxxxxxxxx> wrote:

int n = 42;
char x[n];

Even in this case, x's type is a VLA, but x[999]'s type is char,
so it is not evaluated by sizeof.

Oops, yes. Then what about

int n = 42;
char x[n][n];

sizeof(x[999]);

I can't see how it could cause a problem in practice, because what would
the compiler do with the result of computing x[999] anyway?

I haven't looked at how compilers handle this sort of thing, but I assume
they perform a kind of abstract interpretation in which expressions are
evaluated for their type rather than their value.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
.



Relevant Pages

  • Re: defining the size_t type
    ... (assuming, of course, you have not "#define"d sizeof and/or int). ... the compiler is required ... sizeof and int, and compute the size of an int. ...
    (comp.lang.c)
  • Re: defining the size_t type
    ... (assuming, of course, you have not "#define"d sizeof and/or int). ... the compiler is required ... sizeof and int, and compute the size of an int. ... Note that it must produce this diagnostic on conforming mode. ...
    (comp.lang.c)
  • Re: Find the size of an array
    ... compile time operator then why do I get some warning related to run-time ... sizeof's result is evaluated by the compiler. ... it's forgotten all about the sizeof in the ... is a const int *but NOT an integral constant expression* - a puzzling ...
    (comp.lang.c)
  • Re: Type of variable
    ... Since the preprocessor doesn't know the type ... int i, j; ... To come up with a similar example with sizeof(), ... the compiler does the work of turning sizeofinto 1, ...
    (comp.lang.c)
  • Re: Another sizeof question
    ... Oops, yes. ... int n = 42; ... the compiler do with the result of computing xanyway? ... regarding VLA-typed arguments to sizeof. ...
    (comp.lang.c)

Loading