Article View: comp.std.c
Article #4263Re: Comma operator in constant expression
From: John Rickard
Date: Sat, 21 Oct 1995 11:32
Date: Sat, 21 Oct 1995 11:32
42 lines
2287 bytes
2287 bytes
Paul Long (plong@perf.com) wrote: : Is an implementation required to generate a diagnostic for this : declaration? : : static int i = 1 ? 3 : (1, 2); It seems quite clear that it must generate a diagnostic, as you say. : A constraint in section 6.4 says "Constant expressions shall not : contain ... comma operators..." However, a 6.4 Semantics passage : says "An implementation may accept other forms of constant : expressions." : : This rather large Semantics loophole does not remove the requirement : to generate a diagnostic for the constraint violation though, right? : IOW, an implementation may "accept" a comma operator in a constant : expression, but it must also generate a diagnostic. An implementation would be free to generate a diagnostic and then accept a comma operator even without this `loophole'. Its purpose is presumably to allow an implementation to accept, without a diagnostic, constant expressions that satisfy the restrictions in the Constraints section but do not satisfy the restrictions in the Semantics section. For example, it allows an implementation to accept `(size_t)&((struct s *)0)->m' (which might be generated by the offsetof macro) as a constant expression. But does anyone know what the reason for disallowing comma operators was? I can see an argument that they are unlikely to be useful in constant expressions (though I can find a more or less plausible example of why one _might_ want to use them), but banning them for that reason isn't in the spirit of C. [Quibble: The constraint continues `... except when they are contained within the operand of a sizeof operator'. Does it follow that the expression `1,2' is a valid constant expression in `sizeof(int[1,2])'? Or should `... within the constant expression' be added at the end of the constraint?] -- John Rickard
Technical Details
Message-ID:
<46alp1$or5@gatekeeper.atml.co.uk>Path:
arc1-ca.pugleaf.net!news.atml.co.uk!jrrReferences:
<45uevf$d99@news0.rain.rg.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.atml.co.uk!jrr From: jrr@atml.co.uk (John Rickard) Newsgroups: comp.std.c Subject: Re: Comma operator in constant expression Date: 21 Oct 1995 11:32:49 GMT Organization: Advanced Telecommunications Modules Ltd, Cambridge, UK. Message-ID: <46alp1$or5@gatekeeper.atml.co.uk> References: <45uevf$d99@news0.rain.rg.net> NNTP-Posting-Host: manta.atml.co.uk X-Newsreader: TIN [version 1.2 PL2]