Re: define a struct that has its own type as a field somehow?



In article <ehqenb$29rc$1@xxxxxxxxxxxxxxxxxxx>, Papastefanos Serafeim
<serafeim@xxxxxxxxx> wrote:

"Ben" <x@xxxxx> wrote in message news:261020061450069968%x@xxxxxxxx
Hello,

Is it possible to define a struct that has a type of itself in it?
Thanks, Ben.

Try this
typedef struct _mystruct {
int a;
struct _mystruct *b;
} mystruct;

Serafeim

Yup, thanks. 'struct' infront does it.
Thanks, Ben.
.



Relevant Pages

  • Mixing C and C++
    ... I have therefore implemented the assignment operator to create 'shallow' copy by default (so this is consistent with the C API so that a pointer to the struct could be passed to a C API function with no adverse effect). ... MyStruct(const MyStruct& ms) ... MyStruct& operator= (const MyStruct& rhs) ... void deepcopy ...
    (comp.lang.c)
  • Re: Question about setjmp on Itanium HPUX.
    ... that was the sound of the alignment of your struct ... jmp_buf and your struct. ... The one value which you are guaranteed is safe for struct mystruct is ... Note that in this case, as in your original code, you need to remember ...
    (comp.lang.c)
  • Re: typedefing a struct
    ... typedef struct mystruct { ... typedef struct mystruct mystruct; ...
    (comp.lang.c)
  • Re: Searching a vector of structs
    ... | If you've got a struct like: ... | int x; ... | because it doesn't know how to compare 10 against a MyStruct. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Passing delegates in structure to C dll
    ... I am in no way an expert in P/Invoke, ... IntPtr MyFunctions(IntPtr myStruct); ... The above call boxes the struct (in order to convert it from a ValueType ... pointer to MYSTRUCT.t1, but in fact may point to a .CLR method-table ...
    (microsoft.public.dotnet.languages.csharp)