Re: GCC for i386 allows 'invalid suffix "f" on integer constant'
Re: GCC for i386 allows 'invalid suffix "f" on integer constant'
- Subject: Re: GCC for i386 allows 'invalid suffix "f" on integer constant'
- From: Chris Espinosa <email@hidden>
- Date: Fri, 20 Jan 2006 13:24:37 -0800
On Jan 20, 2006, at 12:39 PM, Dirk Stegemann wrote:
#include <iostream>
int main (int argc, char * const argv[]) {
float f = 2F;
printf("f = %f", f);
return 0;
}
>From the C++ Standard, 2.13.3/1:
A floating literal consists of an integer part, a decimal point, a fraction part, an e or E, an optionally signed
integer exponent, and an optional type suffix. The integer and fraction parts both consist of a sequence of
decimal (base ten) digits. Either the integer part or the fraction part (not both) can be omitted; either the
decimal point or the letter e (or E) and the exponent (not both) can be omitted. The integer part, the
optional decimal point and the optional fraction part form the significant part of the floating literal. The
exponent, if present, indicates the power of 10 by which the significant part is to be scaled. If the scaled
value is in the range of representable values for its type, the result is the scaled value if representable, else
the larger or smaller representable value nearest the scaled value, chosen in an implementation-defined
manner. The type of a floating literal is double unless explicitly specified by a suffix. The suffixes f and
F specify float, the suffixes l and L specify long double. If the scaled value is not in the range of
representable values for its type, the program is ill-formed.
An integer literal is a sequence of digits that has no period or exponent part. An integer literal may have a
prefix that specifies its base and a suffix that specifies its type. The lexically first digit of the sequence of
digits is the most significant. A decimal integer literal (base ten) begins with a digit other than 0 and consists
of a sequence of decimal digits. An octal integer literal (base eight) begins with the digit 0 and consists
of a sequence of octal digits.22) A hexadecimal integer literal (base sixteen) begins with 0x or 0X and
consists of a sequence of hexadecimal digits, which include the decimal digits and the letters a through f
and A through F with decimal values ten through fifteen. [Example: the number twelve can be written 12,
014, or 0XC. ]
The type of an integer literal depends on its form, value, and suffix. If it is decimal and has no suffix, it has
the first of these types in which its value can be represented: int, long int; if the value cannot be represented
as a long int, the behavior is undefined. If it is octal or hexadecimal and has no suffix, it has the
first of these types in which its value can be represented: int, unsigned int, long int, unsigned
long int. If it is suffixed by u or U, its type is the first of these types in which its value can be represented:
unsigned int, unsigned long int. If it is suffixed by l or L, its type is the first of these
types in which its value can be represented: long int, unsigned long int. If it is suffixed by ul,
lu, uL, Lu, Ul, lU, UL, or LU, its type is unsigned long int.
3 A program is ill-formed if one of its translation units contains an integer literal that cannot be represented
by any of the allowed types.
'2' is an integer literal, and only combinations of [ulUL] are allowed for integer literals. '2' is an invalid floating literal, as it has neither a fraction part nor an exponent. It cannot be typed as a float with "F" because it is not a floating literal.
Use 2.F or 2.0F instead.
gcc is incorrect in failing to report the error when compiling with -arch i386, as the program is ill-formed according to the C standard.
Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden