|
|
#1 |
|
"primitive"
I was scribbling up a blather trying to create a definitive, clear explanation of pointers in C, wherein I was making a distinction between primitive and complex data types. The question that arose is what is the largest datum that is/has been treated as a primitive in C? I know of an extended FP type that the x87 unit used/uses that was ten bytes (the M68K FPU used an 80 bit type that embedded two extra bytes for padding), but AFAIK, these are not particularly common.
I regard a "primitive" as something the CPU can handle atomically, but with the prevalence of built-in vector units, the distinction gets blurry. Does C ever treat these big data types as primitives, or is long long the largest primitive in common use today?
__________________
Mr. Paul, sir, I thought you should be advised, there seems to be a zombie tribble clinging to your head, for it is scarfing your brain
|
|
|
|
0
|
|
|
#2 |
|
C doesn't have "primitives". That's all CPU-specific. It's all up to the compiler. There's more than just x86 CPUs in this world you know. And even on the x86, it depends on what mode it is in. I think all that's really specified is that a 'char' is one byte. And an int will be what's "natural" for the CPU. Other than that, it's up to the compiler.
|
|
|
|
0
|
|
|
#3 | |
|
Quote:
To Sydde: Types aren't "primitive" and "complex". They are "fundamental" and "compound". At least that's what they're called in C++. I think C actually has a keyword "complex" these days, so that is a pretty ambiguous term. I'm not sure what your data type size questions have to do with pointers, though. I guess intptr_t would be relevant. |
||
|
|
0
|
|
|
#4 |
|
I normally think of primitive data types as a foil for "complex" types, generally objects in OO languages. In C you can consider a struct complex (and maybe union), but beyond that I don't know what you would be comparing to that would require the primitive distinction. Are you trying to make a case for when passing a pointer costs less memory? This will certainly vary as the size of these types is going to vary wildly. I can't tell you this with certainty, but my understanding is sizeof(short), sizeof(int), sizeof(long), sizeof(long long) can all be equal, and may be larger or smaller than the size of a pointer to any of these types.
I think what this comes down to is letting go of the idea of a primitive in a language that doesn't have user-defined datatypes. Express what you need to express in terms of the data types that are available. -Lee |
|
|
|
0
|
|
|
#5 | |
|
Quote:
So the largest primitive that is standard is likely long double _Complex. In C99, the only type with atomic operations is sig_atomic_t. In C11, you can use _Atomic to specify atomic types, for example _Atomic int x;. Which types are supported is defined by your C11 implementation. |
||
|
|
0
|
|
|
#6 |
|
There's ANSI C, what the processor chips actually do, and what the processor and computer vendors hack into C compilers.
On some processors, FP arithmetic is emulated and float doubles are really implemented as 2 non-atomic 32-bit load/stores. So it may look like a primitive in C code, but can't actually be trusted to behave as such. Apple added short vector intrinsics (NEON, etc.), Intel likewise with SSE, and Cray added some seriously long vector types as "primitive" C data types. So it depends. |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 05:33 PM.







Linear Mode
