On 06/27/2010 08:14 PM, Harald van Dĳk wrote:
> On Sun, Jun 27, 2010 at 05:46:28PM +0300, Nikos Chantziaras wrote:
>> On 06/27/2010 03:23 PM, Harald van Dĳk wrote:
>>> The compiler is not totally free to ignore the register keyword.
>>> Both the C and the C++ standards require that the compiler complain
>>> when taking the address of a register variable. Other compilers will
>>> issue a hard error for it. Fixing the code to not declare the
>>> variable as register would be the correct thing to do.
>> No, it would not be the correct thing to do, because of the following.
>> (This is part of a discussion between me and someone quite smarter than
>> me, who explained the issue in detail.)
> That explanation seems to be written by someone who does not know that
> taking the address of a register variable is simply not allowed.
It is allowed. Section 7.1.1, Paragraphs 2 and 3 of the C++ standard:
The register specifier [...] specifies that the named variable has
automatic storage duration (3.7.3). A variable declared without a
storage-class-specifier at block scope or declared as a function
parameter has automatic storage duration by default.
A register specifier is a hint to the implementation that the variable
so declared will be heavily used. [ Note: the hint can be ignored and in
most implementations it will be ignored if the address of the variable
is taken. This use is deprecated (see D.4). — end note ]
>> OK, long read, but the the conclusion is that "fixing the code to not
>> declare the variable as register would be the correct thing to do" it
>> *not* the correct thing to do. The correct thing to do is to ignore the
>> warning, which is not possible if warnings are turned into errors.
> And which is not possible if the warning is a hard error in the first place.
>> You also mentioned that "other compilers will issue a hard error for
>> it." That sounds rather strange, and I wonder which compilers that
>> might be; someone should file a bug report against them ;)
> Well, let's start with gcc; that's quite an important one for Gentoo...
That code compiles just fine. I don't know of any GCC version that
issues an error for this rather than just a warning.