开发者

Fundamental types

I always thought the following types are "fundamental types", so I thought my answer to this question would be correct, but surprisingly it got downvoted...

Searching the web, I found this. So, IBM says as well those types are fundamental types..

Well how do you interpret the Standard? Are the following types (and similar types), "fundamental types" according to the C++ standard ?

unsigned int
signed char
long double
short int
unsigned short int

EDIT:

Again related to this question: Comceau and gcc dont treat types like "long double", "short int" or "unsigned int" as "fundamental type"! (whereas ibm, intel and microsoft compilers do..) If they did treat such types as fundamental types, following code should compile: short int i = short int()

EDIT:

removed long long types, as i forgot they are not officially s开发者_StackOverflow社区tandard yet..


long long is not supported by the current ISO C++03 standard. However, the C++0x draft standard does include this type:

3.9.1 Fundamental types

2 There are five standard signed integer types : “signed char”, “short int”, “int”, “long int”, and “long long int”.

ISO C99 added this particular data-type (though this was/is available on many compilers as a non-standard extension). C++03 does not fully support all C99 features. Quite a few C++ compilers do however allow this as an extension (e.g. Comeau requires --long_long).


Your logic error in your other answer was already explained by others. To let me explain to you again, given this statement:

The simple-type-specifiers specify either a previously-declared user-defined type or one of the fundamental types.

It does not mean that there are simple-type-specifiers for all fundamental types. It just means that each simple-type-specifier (or a combination of those - i think this sentence is not very clear) specify either a user defined type or one of the fundamental types. That statement also would apply to the following "sample-specifiers":

sample-specifier:
  int
  class-name

Each of my sample-specifiers specify either a previously declared user defined type, or one of the fundamental types (in my case, it's int). It does not mean that all previously declared user defined types can be denoted, nor does it mean that all fundamental types can be denoted. Now if another paragraph in the Standard says that type() works for type being a simple-type-specifier, that does not mean that it also must work for a combination of these. That's a totally invalid conclusion to do.

It's like when i say "decimal digits specify exclusively numbers from 0 to 9" and you say "you are wrong because they can't specify number 10". But what you did was to take a combination of two digits and then claim something i've never said. I think this is a pretty clear logical fallacy you do.


Infact, unsigned/long/short are variant of the int type. So you can use any combination of those keywords together ( like unsigned short int ) ;

But long long is not yet standard : it's supported by many compilers and will be standard in C++0x (the coming standard).


I just took a look in the newest draft of the standard N3035 and it includes an additional table (§7.1.6.2) which lists all valid simple type specifiers and shows that unsigned int and similar types are in fact combinations of simple type specifiers.

simple-type-specifier:
    ::opt nested-name-specifieropt type-name
    ::opt nested-name-specifier template simple-template-id
    char
    char16_t
    char32_t
    wchar_t
    bool
    short
    int
    long
    signed
    unsigned
    float
    double
    void
    auto
    decltype ( expression )
type-name:
    class-name
    enum-name
    typedef-name
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜