Re: Types in C



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?

.



Relevant Pages

  • Re: Types in C
    ... Structs and unions are user-defined. ... 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". ...
    (comp.lang.c)
  • Re: where are unions and bitfields particularly used ?
    ... > instance where I needed to use unions and bitfields(though I have used ... > accessed in unions compared to in structs). ... is an union an user defined data type or a variable. ... Probably to simplify compiler writing. ...
    (comp.lang.c)
  • Re: Dynamically load a dll and us it (in a rexx dll)
    ... The available API functions are dependent on the ODBC version ... The default is usually compiler dependent. ... Depending on the data types used in the structs you ... leave .dll out, it just mentioned path. ...
    (comp.os.os2.programmer.misc)
  • Re: Byte aligned structs
    ... 'data packet' via the serial port. ... structs - i get framing errors for alignment when i apply structs on ... How can i get the compiler to byte align rather than word align. ... routines or macros to insert the shorts and integers for writing and to ...
    (comp.sys.acorn.programmer)
  • Re: Inline Functions?
    ... that is, it suggests that the compiler ... void __cdecl main ... so the complete body of function func() should actually be placed from ... Maybe inline functions only suggests to the compiler that desired ...
    (comp.lang.c)