Why can't constants have commas?

D

Dan Pop

In said:
My code obfuscator gave me this: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

char buff[1, 9];

to which gcc retorted:

"ISO C90 forbids variable-size array 'buff'"


I'd imagine an Integer constant is needed here.

What is the "1" in 1,9 doing here anyway? Declaring an array indexed
1..9? Declaring a 2 dimensional array [0..1] [0..8]? I'm not surprised
the compiler complained, so would I!

I'm not too knowledgeable about C so not sure what A,B might mean
except evaluate A then B, or vice versa. But that doesn't explain
meaning of [1,9] in this context.

What part of "My code obfuscator gave me this" was too difficult for you
to understand?

Dan
 
D

Dan Pop

In said:
(e-mail address removed) (Old Wolf) writes:
[...]
BTW this whole thread shows how ridiculous VLA is, the sooner
the standards committee retracts their mistake, the better.

Don't hold your breath. VLAs have been implemented, and code has been
written that depends on them.

I kinda doubt it, given the "wide" availability of conforming C99
implementations.

Most of the code using VLAs is GNU C code using GNU C VLAs, rather than
C99 code using C99 VLAs (the two kinds of VLAs are not semantically
equivalent).
The committee isn't going to break existing code like that.

VLAs should have been introduced in C89. They are the right solution
for any kind of code doing matrix processing in C, but they're coming
far too late.

Dan
 
B

Bart

What part of "My code obfuscator gave me this" was too difficult for you
to understand?

Dan

Actually, I saw the 'obfuscator' bit after I posted my message.. Even
so, I think the content still stands.

It seems that ' char buff[a,b]' just means 'buff' in C? In which
case I would expect the compiler to remark on the 'a,' bit, which it
has (with a misleading error message). And also in this case a
'de-obfuscator' could just remove the extraneous code.

(I also thought that 'char buff...' seemed quite sensible output of
the obfuscator..)

Bart.
 
D

dandelion

Dan Pop said:
In <[email protected]> "dandelion"

Just as 1+9 invariably evaluates to 10, yet it is a valid constant
expression and can be used in an array declaration.

Which is at least something different than I wrote.
Bogus conclusion.

Not a conclusion at all. Merely a statement of my view that such a
declaration would be a bit weird.

So your "Bogus conclusion" conclusion is Bogus.

Thankyouverymuch...
 
J

John Bode

Kevin Bracey said:
In message <[email protected]>
Arthur J. O'Dwyer said:
Yeah, well, in this case Peter isn't asking for it to be constant;
function calls are definitely not constant initializers, whether in
static-variable initializations or in array sizes. But the sequence
<const-expression> , <const-expression>
never has weird side effects, so that's not a problem.

I thought maybe it had something to do with the fact that the comma
operator introduces a sequence point---what does it mean to have a
sequence point in the middle of a variable declaration?! But it appears
that C has no problem with the sequence points in

int a[1&&9];
int b[1||9];

I have heard the theory that it's a specific and deliberate design decision,
with the express purpose of making the beginner's error

int c[1,9];

a constraint violation. Otherwise, silly code like this would actually
compile and run:

int a[5,5], x, y;

for (x=0; x<5; x++)
for (y=0; y<5; y++)
a[x,y] = x*y;


But think of the possibilities that could open up for the IOCCC...
 
D

Dan Pop

In said:
It seems that ' char buff[a,b]' just means 'buff' in C?


It *would*, if the comma operator were allowed in constant expressions.
In which
case I would expect the compiler to remark on the 'a,' bit, which it
has (with a misleading error message).

The compiler must complain, because a,b is not a valid constant
expression. It need not generate a meaningful complaint, however :)
And also in this case a
'de-obfuscator' could just remove the extraneous code.

Most of the changes performed by obfuscators can be undone.
(I also thought that 'char buff...' seemed quite sensible output of
the obfuscator..)

Any obfuscator that doesn't translate all local names in combinations
of two characters (O and 0 or 1 and l) is not a real obfuscator.

Dan
 
D

Dave Thompson

(For C99 no longer for automatic arrays, as already noted.)
1+9 is a constant expression. Why not have 1,9 a constant expression as
well?

If you had something like this:

enum stuff { gork = (1,9) };

void poo(void)
{
char buff[gork];
}

Would that be legal? If so, then substituting
(1,9) for gork in the buff declaration should
also be legal.

No. enum values also must be (integer) constant expressions.

- David.Thompson1 at worldnet.att.net
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top