[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: bug in gcc?
- From: Sam Roberts <sroberts@...>
- Date: Wed, 4 Apr 2007 14:18:16 -0700
On Wed, Apr 04, 2007 at 09:37:08PM +0100, David Given wrote:
>  Notice that 'usually'? This is the reason why x("hi") works. In an
> incredibly brain-damaged fit of, well, something, the C++ designers decided
> that it would be convenient if constant strings could be implicitly cast to
> char*. But this only happens if the constant string is *directly* cast to a
> char*. If you do an operation on it first, the const char* type is used
> instead. So:
> x("hi"); // works.
> x("hi"+1); // fails!
Well, in fairness to the C and C++ folks, I don't think either standard
specified whether a string literal is const or not, and lots of code
assumes they aren't const. Its started to default to const recently with
gnu, IIRC, because it allows linkers to unify all identical string
literals, an optimization that would not be safe if they could be
changed. And Stroustrup (in design and evolution of c++) laments that
there were some things he wanted to be illegal but that were so common
he had to allow them. int to char assignments, for example.
> Besides, can luaL_error() fail?
Doesn't appear so from reading the code, not in lua 5.0 anyhow.
I don't really mind the idiom, though I don't use it myself. Most
non-lua library functions that don't return - abort(), longjmp(), exit()
- return void. C programmers are used to dealing with this, even without
is pretty typical and portable. So is
... code when there isn't an error