Re: Types in C
- From: Uncle Steve <stevet810@xxxxxxxxx>
- Date: Mon, 23 May 2011 19:23:39 -0400
On Mon, May 23, 2011 at 10:24:31PM +0000, Seebs wrote:
On 2011-05-23, Uncle Steve <stevet810@xxxxxxxxx> wrote:
There are no "user defined" types in C.
Sure there are!
Oh, no there aren't!
Structures and unions are
aggregates of basic types (and structures/unions).
Sure.
So? Doesn't make them not types. Pointers, arrays, enums, structs,
unions... all types. Structs and unions are user-defined. And they are
types. This makes them... *drumroll* user-defined types.
Not if we make a finer distinction between types. As I see it there
are two types of types:
char, int, long, float, void *, etc. are /basic types/ fundamental to
the implementation of the C language (and arithmetic operations).
Compound types are aggregates of these basic types as well as compound
types. There's a fundamental difference you are ignoring given a
sufficient vague definition of 'type'.
A real user-defined type would be something new like the complex
numbers extension in gcc. I don't do much OOP, but someone here
probably knows of a language that allows new fundamental type
definitions without direct compiler support. C requires compiler
support for this. So, if you want a 128-byte integer type either you
modify the compiler to emulate arithmetic operations with smaller asm
instructions, or you write a library to handle it.
BTW, have a look at the gmp.h header and note that they do not shy
away from macro-like functions. Not that I care a whole lot, but I'd
say the writers of the gmp library probably know more than you do
about the suitability of inline functions versus macros and when to
use each. Just a 'feeling' on the matter, which is not to say that
you're entirely wrong.
I would guess that one of the times to use macros is "when you have to
be portable to compilers that don't have inline functions". That's
definitely a key application.
gmp is well into version 4; I doubt it would compile where there is no
support for inline functions, but I have not verified this.
Regards,
Uncle Steve
--
Should a professional politician be charged with molestation if he
kisses babies while attending political rallies?
.
- Follow-Ups:
- Re: Types in C
- From: Seebs
- Re: Types in C
- References:
- Re: Types in C
- From: jacob navia
- Re: Types in C
- From: Keith Thompson
- Re: Types in C
- From: Seebs
- Re: Types in C
- From: jacob navia
- Re: Types in C
- From: Keith Thompson
- Re: Types in C
- From: Ian Collins
- Re: Types in C
- From: Uncle Steve
- Re: Types in C
- From: Seebs
- Re: Types in C
- Prev by Date: Re: Types in C
- Next by Date: Re: Types in C
- Previous by thread: Re: Types in C
- Next by thread: Re: Types in C
- Index(es):
Relevant Pages
|