Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: memcpy not memcpying? Date: Mon, 04 Nov 2019 20:58:51 -0800 Organization: A noiseless patient Spider Lines: 34 Message-ID: <868sougbqs.fsf@linuxsc.com> References: <2LVuF.7$BF1.0@fx26.iad> <6KfvF.57888$rJ1.57717@fx01.am4> <0DivF.23103$Q26.16540@fx34.am4> <1BAvF.13970$mB7.12243@fx32.am4> <%%DvF.115593$Yl3.480@fx24.am4> <87eeynlwc7.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="59b683b75f73ead2c1b20aa011ddc5ef"; logging-data="18855"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19o06RwSU4E6xHpWZlJqIzQEMpfZquT+oE=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:l9Fn/HRhLkG62cWKCEoaD+pqxHE= sha1:krnGvTwocY/ZfUkedrwmk51g3e8= Xref: csiph.com comp.lang.c:147591 Keith Thompson writes: > Ben Bacarisse writes: > [...] > >> I think I might use _Generic here because checking the size is not >> always going to be enough: >> >> _Static_assert( >> _Generic(i, int: 1, default: 0), >> "Check this because symbolcount_t is not compatible with int." >> ); >> >> This works (in both clang and gcc) with -std=c11 -pedantic, but I am not >> sure that _Generic /must/ be allowed here. It would be a shame if >> generic selections were not considered to be standard constant >> expressions. Have I missed something in the standard? > > I think it's covered in 6.6, which has this contraint in p2: > > Constant expressions shall not contain assignment, increment, > decrement, function-call, or comma operators, except when they > are contained within a subexpression that is not evaluated. > > Which implies, I think, that a generic selection is a constant > expression if the result expression is a constant expression, > even if the other subexpressions are not. What a strange inference. The quoted sentence can tell us only when an expression is not a constant expression, never when it is a constant expression. Besides which, a _Static_assert needs not just a constant expression but an integer constant expression.