Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: aotto1968 Newsgroups: comp.lang.c Subject: Re: I want to use the g++ template in the "C" gcc software Date: Thu, 12 Dec 2024 16:17:19 +0100 Organization: A noiseless patient Spider Lines: 72 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 12 Dec 2024 16:17:19 +0100 (CET) Injection-Info: dont-email.me; posting-host="59a33ca877caa9bec583b79c4220afa6"; logging-data="2305233"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19swywD1DokGiNVTggk4TVRalc//1dK9ZI=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:AG9u791Uc2aM0Sr9TlDhuZCpzgE= Content-Language: en-US In-Reply-To: Bytes: 5237 On 12.12.24 11:24, David Brown wrote: > On 12/12/2024 09:37, aotto1968 wrote: >> Hi, >> >> I create a C software and there is a requirement to use the g++ template *in* the gcc. >> I do *not* want to use all the g++ "boilerplate" like special syntax, classes etc >> I just want to use the template. >> >> goal: >> >> 1. I already use "inline" code to replace "cpp-macro-like" syntax in the header. >> 2. NOW I *want* to replace a "cpp-macro" which use the *data-type* as an argument with a template. >> >> question. >> >> 1. Is there a g++ switch to disable all the g++ features except of C source and template feature ? >> 2. Is there a gcc switch to add g++-template feature into gcc ? >> 3. is there an external software to add the c++-template feature into an existing C software ? >> >> thanks. > > It might help if you give an example of what you are trying to achieve - it doesn't have to be valid code that can be compiled. > > gcc has command-line options to disable some features of C and C++, but not like you are describing.  And C++ without classes is > not the same as C anyway.  But you might find you can write your code in C++ and simply not use the features you don't want to use. > > If you are trying to make type-generic function-like "things" in C, then you have to use macros.  But you can use modern > features of C11 and C23 to make this safer and neater than in older C standards.  gcc also provides extensions that can help, if > you are happy writing gcc-specific code. > > You should do your own googling for information, tutorials and examples here, but these links will give you some starting points: > > C11 _Generic selections: > > > C23 "typeof" and "auto" type inference: > > > > gcc extensions: > > > Thanks for your links but I already know "feature" of gcc etc… I still want to get better "macro" code use template like c++ has example: (the 'cls' is a type and the `pBufferInit_T` create a type specific "inline" -> this I want to replace with an template. #define pBufferInit_T(pre, cls) \ mk_inline void \ p##cls##Init ( \ MK_RT_ARGS \ pre##cls##C##R * const loc, \ MK_TYP const type, \ MK_NUM const size \ ) { \ pppBufferInit(MK_RT_CALL pre##cls##C##_X2buf(loc),size, \ (MK_NUM)((*type).objsize-sizeof(pre##cls##C##R)), \ offsetof(pre##cls##C##R,ils_data)); \ if (type->objsig != (*pre##cls##C##_X2obj(loc)).signature) { \ (*pre##cls##C##_X2obj(loc)) = MkObjInitFromType(type,true /* isLocal */); \ } \ /* ppBufferInit */ \ /* ppBufferStreamInit */ \ pp##cls##Init(MK_RT_CALL loc); \ /* pBufferReset */ \ /* pBufferStreamReset */ \ p##cls##Reset(loc); \ } \