Re: struct-functions in C

From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 09/09/04


Date: Thu, 09 Sep 2004 12:04:17 +0100

In article <%1W%c.256960$vG5.154641@news.chello.at>, marbac
<marbac@chello.at> wrote:
>
> is a function within a struct allowed in C or is this only allowed in C++?

No, 'struct's are for data; putting a function within a 'struct' would
have no meaning in C. But pointers to functions are OK, and you could
even simulate some sort of object-oriented capability that way, though
it's not something I would advise to a beginner.

Alwyn



Relevant Pages

  • Re: Simple question, err... I think
    ... Your nodes contain no other indication of which pointers are valid, ... struct CountedObject ... int is_red; ... bool lament(char const s) ...
    (comp.programming)
  • Re: big-little
    ... so, the gain is a type-system where I can use raw pointers, do most other things one can do with raw pointers, run type-checks on whatever, where adding types is often as simple as coming up with a name for it. ... similarly, one can register a few callbacks and add new types of built-in objects to the language, ... ... theoretically, one can just shove a lambda into a function pointer (say, in a struct or similar) and it should work, but I don't currently trust this all that well. ... C code generation can be skipped if one doesn't really need transparent C -> script calls (and can live with making API calls, or writing wrapper functions for said API calls...). ...
    (comp.arch)
  • Re: porting problems encountered
    ... Tru64 compiles long variables to size 8 bytes while VMS and HP-UX ... platform, the size of the structure would be 12 bytes. ... when it got to the AS/400 with 128 bit pointers. ... Using the struct from before: ...
    (comp.os.vms)
  • Re: strict aliasing rules in ISO C, someone understands them ?
    ... I understand now that my interpretation of the standard was totally ... an aggregate is a struct or an array. ... struct s1 {int i; double d;}; ... Pointers are just a means of accessing the objects, ...
    (comp.lang.c)
  • Re: Array of pointers in a struct
    ... >typedef struct trieNode ... This is an array of 27 pointers. ... >And this is the code I make a new trie node, initialize and return it. ...
    (comp.lang.c)