tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Re: static const not recognized as const value?


From: Jared Maddox
Subject: [Tinycc-devel] Re: static const not recognized as const value?
Date: Mon, 27 Dec 2010 16:37:53 -0600

> Date: Mon, 27 Dec 2010 14:50:06 +0100
> From: Stephan Beal <address@hidden>
> Subject: [Tinycc-devel] static const not recognized as const value?
> To: address@hidden
> Message-ID:
>        <address@hidden>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi, TCCers!
>
> (This is my first post to the list.)
>
> Every now and then i write code like the following:
>
> static const size_t sz = 1024 * 2;
> char buffer[sz];
> ...
>
> tcc complains that sz is not a constant expression, which "just doesn't seem
> right" to me. It does of course accept:
>
> enum { sz = 1024 * 2 };
> char buffer[sz];
>
> but i'm quite pedantic about type safety, and hate having to cast my enum
> values to size_t (or whatever) during later calls which use the "sz" value.
>
> Is there a particular reason which tcc  (0.9.25) doesn't recognize static
> consts as const values? i understand that tcc doesn't support C99 vararrays,
> but a static const isn't quite the same as using, e.g., a value passed to
> the function as the array size. (Or maybe they are the same, from tcc's
> point of view?) This behaviour has been, in recent months, the only place i
> have to retroactively change code to make it work in tcc.
>
> :-?
Although the array can be allocated at compile-time, the example you
provide is almost guaranteed to be classified as a vararray by the
standard. I'm afraid you'll have to store the actual value in either a
define or an enum, and initialize the variable and array from that
instead of doing it directly.

Incidentally, why are you being pedantic on size_t? Are you worried
about accidentally exceeding it's bounds? By only using the enum to
initialize the array and variable, and then using the variable
everywhere else, you should be able to get the accurate figure
everywhere, even if it isn't always the 'right' value.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]