This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: -Wimplicit-signed-char


Andreas Schwab writes:
> Jamie Lokier <jamie.lokier@cern.ch> writes:
> |> Russell King wrote:
> |> > 	char ch;
> |> > 	do {
> |> > 		ch = getopt(...);
> |> > 		...
> |> > 	} while (ch != EOF);
> |> > 
> |> > The above fragments of code compile cleanly on architectures which default
> |> > to signed chars.
> |> 
> |> However, the EOF fragment is broken whatever the signedness :-)
> |> Use `int ch'.
> 
> Moreover, getopt does not actually return EOF, but -1.

Correct, so the above is broken for more reasons than just the 'char'
part.

The only reason it happens to work is because of an implementation chose
the value "-1" to mean EOF.
   _____
  |_____| ------------------------------------------------- ---+---+-
  |   |         Russell King        rmk@arm.linux.org.uk      --- ---
  | | | |   http://www.arm.linux.org.uk/~rmk/aboutme.html    /  /  |
  | +-+-+                                                     --- -+-
  /   |               THE developer of ARM Linux              |+| /|\
 /  | | |                                                     ---  |
    +-+-+ -------------------------------------------------  /\\\  |

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]