Re: obj function hello()



gert wrote:
i started from python actually. I was trying to figure out how to make
a struct that has data and functions defined in the struct it self ?

Please keep the context you are replying to.

You can't have functions in structs in C. What yo can have is function
pointers:

struct Obj {
int someInt;
int (*someFn)(void);
};

But you have to assign a function address to the pointer for each
instance of Obj.

--
Ian Collins.
.



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: 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)
  • Re: How are C++ objects laid out in memory ?
    ... If a C++ class or struct contains no virtual methods, ... There are no function pointers. ... >pointers which I can locate and then invoke the function pointers? ...
    (comp.lang.asm.x86)