Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 10, 2013, 12:12 AM   #1
Sydde
macrumors 68000
 
Sydde's Avatar
 
Join Date: Aug 2009
"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?
__________________
You got to be a spirit. You can't be no ghost.
Sydde is online now   0 Reply With Quote
Old Feb 10, 2013, 01:17 AM   #2
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: San Diego, CA USA
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.
mfram is offline   0 Reply With Quote
Old Feb 10, 2013, 01:42 AM   #3
jon3543
macrumors 6502
 
Join Date: Sep 2010
Quote:
Originally Posted by mfram View Post
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.
There are minimum ranges for each of the fundamental data types, and while "char" and "byte" are synonymous, a C "byte" can be larger than 8 bits (which is the minimum size to provide the required range for the char data types).

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.
jon3543 is offline   0 Reply With Quote
Old Feb 10, 2013, 01:44 AM   #4
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
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
lee1210 is offline   0 Reply With Quote
Old Feb 10, 2013, 04:15 AM   #5
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by Sydde View Post
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?
The largest integer types supported by your compiler are int_max_t and uint_max_t (which on MacOS X compilers are defined as long long and unsigned long long). Pointer types can be different sizes. The largest real type is long double, 16 bytes on every current MacOS X compiler. C also supports complex numbers which are considered primitives, so the largest one would be long double _Complex. Compilers on MacOS X have "small vector" extensions; these would also be primitive types.

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.
gnasher729 is offline   0 Reply With Quote
Old Feb 10, 2013, 11:43 AM   #6
firewood
macrumors 603
 
Join Date: Jul 2003
Location: Silicon Valley
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.
firewood is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Save "gray scale" and "max contrast" via Universal Access in screen captures NeonKingKong OS X 2 Jun 2, 2013 09:09 PM
2010 27" iMac screen issue..."dirty", "cloudy", image retention issues MMcCraryNJ iMac 1 May 18, 2013 04:02 PM
My Logic "track expander tube" doesn't have "end tips" to grab! Whats up? kristenanne77 Digital Audio 3 Mar 28, 2013 08:15 AM
Resolved: Weird problem with keyboard mapping : LMP Bluetooth Keypad's "enter" seen as "CMD" DanRom iMac 2 Aug 24, 2012 12:27 AM
Start a new tab similar to "iOS blog" and "Mac blog" but make it "IPhone Leaks?" Dewroo Site and Forum Feedback 2 Aug 23, 2012 09:47 AM

Forum Jump

All times are GMT -5. The time now is 09:35 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC