Data type Qualifers

R

Rod Pemberton

Ben Pfaff said:
const, restrict, and volatile

Type qualifiers modify the way the data is used or accessed. Many
non-standard "attributes" are implemented as type qualifiers: cdecl,
stdcall, __fastcall, __w64, __thread, noreturn, __malloc__, format,
__attribute, __attribute_used__, __declspec, etc.

Pre-ANSI versions of C usually #define const, restrict, or volatile to
nothing. If your C code doens't work properly without the type qualifiers,
you have a coding error. Using a type qualifier to _fix_ a problem should
be a 'red flag' that something is incorrect.


Rod Pemberton
 
B

Ben Pfaff

Rod Pemberton said:
Type qualifiers modify the way the data is used or accessed. Many
non-standard "attributes" are implemented as type qualifiers: cdecl,
stdcall, __fastcall, __w64, __thread, noreturn, __malloc__, format,
__attribute, __attribute_used__, __declspec, etc.

In the implementations that I am familiar with, the __thread
extension is a storage class, not a type qualifier.
 
K

Keith Thompson

Rod Pemberton said:
Pre-ANSI versions of C usually #define const, restrict, or volatile to
nothing.

No. Code intended to run on pre-ANSI C implementations may #define
them to nothing, but the implementations themselves wouldn't do so.
 
E

Eric Sosman

Rod said:
Type qualifiers modify the way the data is used or accessed. Many
non-standard "attributes" are implemented as type qualifiers: cdecl,
stdcall, __fastcall, __w64, __thread, noreturn, __malloc__, format,
__attribute, __attribute_used__, __declspec, etc.

Pre-ANSI versions of C usually #define const, restrict, or volatile to
nothing. If your C code doens't work properly without the type qualifiers,
you have a coding error. Using a type qualifier to _fix_ a problem should
be a 'red flag' that something is incorrect.

I'd agree for `const' and `restrict', but not for
`volatile'.

int func(void) {
jmp_buf buff;
int value = 0;
while (setjmp(buff) == 0) {
otherfunc(value++);
}
return value;
}

This code has an error, and the fix is to add `volatile'
to the declaration of `value'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,949
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top