Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is long a data type or qualifier in C?

Tags:

c

I am reading Programming in C by Stephan G. Kochan. He states that C has only five data types; int, float, double, char and _Bool.

What about long? Isn't it a builtin type? http://www.programiz.com/c-programming/c-data-types says long is a qualifier to modify the size. If it is a qualifier then it should be only used as a long int, and not as a standalone long.

And what about _Bool? Many Internet tutorials say there is no boolean type in C.

Related:

  • Is long long a type in C?

  • Is "long long" = "long long int" = "long int long" = "int long long"?

like image 549
Wafeeq Avatar asked Jun 23 '16 08:06

Wafeeq


People also ask

What are data type qualifiers in C?

In the C, C++, and D programming languages, a type qualifier is a keyword that is applied to a type, resulting in a qualified type. For example, const int is a qualified type representing a constant integer, while int is the corresponding unqualified type, simply an integer.

Is short a qualifier in C?

“short” is the qualifier and “int” is the basic datatype. If you are interested in learning Programming Languages that will enhance your job opportunities, then check out the Programming classes from Intellipaat.


2 Answers

He states that C has only five data types; int, float, double, char and _Bool.

That's quite an over-simplification. Maybe intentional, if the book is aimed towards beginners.

If you go through C11 6.2.5 it lists the following distinct data types:

Character types (6.2.5/15)

char signed char unsigned char 

Standard signed integer types (6.2.5/4)

signed char short int int long int long long int 

Standard unsigned integer types (6.2.5/5)

_Bool unsigned char unsigned short int unsigned int unsigned long int unsigned long long int 

Real floating types (6.2.5/10)

float double long double 

Complex types (6.2.5/11)

float _Complex double _Complex long double _Complex 

Enumerated type (6.2.5/16)

enum {} 

void type (6.2.5/19) (void type is an incomplete type)

void 

Derived types (6.2.5/20)

  • Array type
  • Structure type
  • Union type
  • Function type
  • Pointer type
  • Atomic type

Formally the term is type specifier 6.7.2:

type-specifier: void char short int long float double signed unsigned _Bool _Complex atomic-type-specifier struct-or-union-specifier enum-specifier typedef-name 

At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
— void
— char
— signed char
— unsigned char
— short, signed short, short int, or signed short int
— unsigned short, or unsigned short int
— int, signed, or signed int
— unsigned, or unsigned int
— long, signed long, long int, or signed long int
— unsigned long, or unsigned long int
— long long, signed long long, long long int, or signed long long int
— unsigned long long, or unsigned long long int
— float
— double
— long double
— _Bool
— float _Complex
— double _Complex
— long double _Complex
— atomic type specifier
— struct or union specifier
— enum specifier
— typedef name

As we can see, long is a type specifier. It is not a type qualifier.

like image 93
Lundin Avatar answered Oct 14 '22 09:10

Lundin


From the C11 draft, section 6.2.5 ("Types)" paragraph 4:

There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int.

How these types are specified in program text is another issue, there are many ways since the syntax is rather lax. For instance, according to 6.7.2 ("Type Specifiers") the following are all valid ways to specify the same type:

long, signed long, long int, or signed long int

This says that long by itself is a valid type specifier for the type long int. This was the same in C99 (and, I would guess, earlier standards too). So no, it's not a qualifier.

In addition, the above can be intermixed with things like static, volatile, pointer asterisks, and so on.

I would suggest reading some other book, since it's confusing to read books that use different terminology from the standard. The standard is often refered to when answering questions about C, so it's a good idea to be familiar with it.

like image 21
unwind Avatar answered Oct 14 '22 10:10

unwind