On Fri, 2010-06-11 at 08:44 +0800, yuanbin wrote: > typedef struct CBase { int i; } CBase; > typedef struct CT1 { EXTENDS(CBase) ... } CT1; > typedef struct CT2 { EXTENDS(CT1) ... } CT2; > ... > typedef struct CTN { EXTENDS(CTN_1) ... } CTN; > CTN t; > t.i=1; //need not t.CTN_1....CT2.CT1.CBase.i ---complex > CBase* p=&t.CBase; //need not t.CTN_1....CT2.CT1.CBase, need not > (CBase*)&t ---not safe
struct CBase { int i; }; struct CT1 : CBase { ... }; struct CT2 : CT1 { ... }; struct CTN : CTN_1 { ... }; CTN t; t.i = 1; // assumes this is in function scope CBase* p = &t; // Even simpler than your proposal and still safe. Yep, this is valid C++. I think Dave is right, you really want C++. /MF > > 2010/6/11 Dave Korn <dave.korn.cyg...@gmail.com>: > > On 10/06/2010 18:07, yuanbin wrote: > >> This compiler's extension is valuable > > > > No, it isn't very valuable, sorry to be blunt. I think you are following a > > really wrong path here. You are trying to implement a C++-alike > > object-oriented system in C. That makes sense as far as it goes, but if you > > find yourself having to propose modifying the C compiler in a direction that > > basically makes it speak C++, you might as well just use C++ in the first > > place. You want the compiler to automatically choose one of several > > different > > ways to initialise a union according to the data type of the argument you > > use > > to initialise it with; basically, that means you want overloaded > > constructors. > > So you should just use C++, which already is C with overloaded > > constructors. > > And it also already has all the other features that you'll discover you > > need > > in the compiler as you carry along this path. > > > > By the time you get to the end of your journey, "coo.h" will be an empty > > file and all the functionality will have been added to the C compiler until > > it > > turns into a C++ compiler. I think you need to choose a different plan. > > > > cheers, > > DaveK > > > >