On 2022-07-30 19:48:29 +0200, grischka wrote: > On 30.07.2022 12:45, Vincent Lefevre wrote: > > I changed the & to && because it is more correct and makes more sense, > > but note that this is not really redundant because n is signed and > > n & (n - 1) is not portable when n = 0 or 1 if two's complement isn't > > necessarily used, because 0 may have several representations (well, > > tcc is not designed to work on such exotic platforms, but who knows > > in the future... and moreover, because of this general portability > > issue, compilers may issue warnings). > > Sorry, what? Are you saying that (n & (n - 1)) with n == 1 -> (1 & 0) > and with n == 0 -> (0 & -1) does not evaluate to 0 in both cases always > necessarily, in C?
Yes, if the 0 happens to be a negative 0, 1 & 0 will give 1 in ones' complement, and 0 & -1 will also give non-zero in both ones' complement and "sign and magnitude". ISO C17 says: It is unspecified whether these cases actually generate a negative zero or a normal zero, and whether a negative zero becomes a normal zero when stored in an object. > > > As to the "n < 0 ||" clause by the way. the C-standards seem to say: > > > > > > "Alignments are represented as values of the type size_t. Valid > > > alignments > > > include only fundamental alignments, plus an additional > > > implementation- > > > defined set of values, which may be empty. Every valid alignment > > > value > > > shall be a nonnegative integral power of two." > > > > > > Well, when "size_t" means unsigned, how could it be not "nonnegative" > > > then ?!? > > > > I don't understand what you mean here. The fact is that in the code, > > n is of type int, not size_t. So the case n < 0 needs to be taken > > into account. Note that n comes from > > > > n = expr_const(); > > > > thus may be negative. > > Seems I have misunderstood what they are trying to say. It seems that by > "nonnegative integral power of two" > they mean any powers 0..n of two, as in > 2 ^ 0..n > as opposed to > 2 ^ -1.2 > for example. > > That hasn't to do much with "int n = expr_const();" in tcc though because > the 'n' there does not mean "2 ^ n", just as _Alignas(1) does not mean > to align at 2 ^ 1. It means to align at 2 ^ 0 = 1. The point is that _Alignas(-2) is invalid. > Therfor the combination > > if (n < 0 || ... > tcc_error("alignment must be a positive power of two"); > > still seems misleading. "_Alignas(0x80000000) int x;" is not an > invalid declaration, per se. Well, this depends on the implementation. If supported by tcc, this is fine. But this should be documented, as this is an implementation-defined feature. -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon) _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel