Re: if(a);
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 05/11/04
- Next message: Arthur J. O'Dwyer: "Re: Without semicolons"
- Previous message: Nick Landsberg: "Re: static initialization"
- In reply to: Mark McIntyre: "Re: if(a);"
- Next in thread: Martin Johansen: "Re: if(a);"
- Reply: Martin Johansen: "Re: if(a);"
- Reply: Jack Klein: "Re: if(a);"
- Reply: Ben Pfaff: "Re: if(a);"
- Reply: Douglas A. Gwyn: "Re: if(a);"
- Reply: Dan Pop: "Re: if(a);"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 10 May 2004 19:54:26 -0400 (EDT)
[NB: xpost to comp.std.c added]
On Mon, 10 May 2004, Mark McIntyre wrote:
>
> Martin Johansen wrote:
> > if(a);
> >
> > In this code, to what type does the if statement cast the variable
> > "a" on comparison?
>
> a isn't cast to any type. A cast is when the programmer deliberately
> types extra stuff eg
> (sometype) foo;
> casts foo to a sometype object.
For the OP's benefit: The correct term for something that "acts
like a cast" without the explicit "(sometype)" is an "implicit
conversion."
> Back to your original question: 'a' has to be an integral type, or
> something that can be converted to an integral type.
As Ben said, not quite. 'a' has to be a type which can be
validly compared for equality with 0. That is, the line
if (a) ;
is exactly equivalent to the line
if ((a) == 0) ;
no matter what the type of 'a' is. If 'a' doesn't have the right
type for that second line to make sense, then the first line is
invalid as well.
Crosspost to c.s.c added because of the following...
Question for the experts: Does the C standard clarify what it
means by "compare equal to 0" anywhere? Is that 0 the literal 0
of type 'int', or the value you get by converting 0 to the type
of 'a'? Is there any valid C program that could tell the difference?
-Arthur
- Next message: Arthur J. O'Dwyer: "Re: Without semicolons"
- Previous message: Nick Landsberg: "Re: static initialization"
- In reply to: Mark McIntyre: "Re: if(a);"
- Next in thread: Martin Johansen: "Re: if(a);"
- Reply: Martin Johansen: "Re: if(a);"
- Reply: Jack Klein: "Re: if(a);"
- Reply: Ben Pfaff: "Re: if(a);"
- Reply: Douglas A. Gwyn: "Re: if(a);"
- Reply: Dan Pop: "Re: if(a);"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|