Gentoo Archives: gentoo-dev

From: Nikos Chantziaras <realnc@×××××.de>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: FYI: Rules for distro-friendly packages
Date: Sun, 27 Jun 2010 17:48:50
Message-Id: i082ss$v2j$1@dough.gmane.org
In Reply to: Re: [gentoo-dev] Re: FYI: Rules for distro-friendly packages by "Harald van Dijk"
1 On 06/27/2010 08:14 PM, Harald van Dijk wrote:
2 > On Sun, Jun 27, 2010 at 05:46:28PM +0300, Nikos Chantziaras wrote:
3 >> On 06/27/2010 03:23 PM, Harald van Dijk wrote:
4 >>> The compiler is not totally free to ignore the register keyword.
5 >>> Both the C and the C++ standards require that the compiler complain
6 >>> when taking the address of a register variable. Other compilers will
7 >>> issue a hard error for it. Fixing the code to not declare the
8 >>> variable as register would be the correct thing to do.
9 >>
10 >> No, it would not be the correct thing to do, because of the following.
11 >> (This is part of a discussion between me and someone quite smarter than
12 >> me, who explained the issue in detail.)
13 >>
14 >> [snip]
15 >
16 > That explanation seems to be written by someone who does not know that
17 > taking the address of a register variable is simply not allowed.
18
19 It is allowed. Section 7.1.1, Paragraphs 2 and 3 of the C++ standard:
20
21 The register specifier [...] specifies that the named variable has
22 automatic storage duration (3.7.3). A variable declared without a
23 storage-class-specifier at block scope or declared as a function
24 parameter has automatic storage duration by default.
25
26 A register specifier is a hint to the implementation that the variable
27 so declared will be heavily used. [ Note: the hint can be ignored and in
28 most implementations it will be ignored if the address of the variable
29 is taken. This use is deprecated (see D.4). — end note ]
30
31
32 >> OK, long read, but the the conclusion is that "fixing the code to not
33 >> declare the variable as register would be the correct thing to do" it
34 >> *not* the correct thing to do. The correct thing to do is to ignore the
35 >> warning, which is not possible if warnings are turned into errors.
36 >
37 > And which is not possible if the warning is a hard error in the first place.
38 >
39 >> You also mentioned that "other compilers will issue a hard error for
40 >> it." That sounds rather strange, and I wonder which compilers that
41 >> might be; someone should file a bug report against them ;)
42 >
43 > Well, let's start with gcc; that's quite an important one for Gentoo...
44
45 That code compiles just fine. I don't know of any GCC version that
46 issues an error for this rather than just a warning.

Replies

Subject Author
[gentoo-dev] Re: FYI: Rules for distro-friendly packages dev-random@××××.ru