Johannes Bauer <>, on 29/07/2010 22:46:15, wrote:
> Am 29.07.2010 19:53, schrieb Andrey Tarasevich:
>> Johannes Bauer wrote:
>>> No, initialized data is fine (viewing initialized data as a subset of
>>> uninitialized data). Anything which was omitted may well be set to 0 or
>>> 0xffffffff or whatever the compiler likes - if it only would allow me to
>>> omit it (like the C compiler does).
>>
>> Like _C99_ compiler does. If you want your code to be portable across
>> C89/90, C99 and C++ you have no other choice but to use either "no
>> initializer+assignment" approach or "supply all initializers beginning
>> from the first" approach.
>
> Well, that's no real nice solution. The struct has around 150 actual ISR
> handlers and I want to set some specific ones without having to know
> where they all need to be placed in memory.
What is so ugly with the "no initialized + assignment" approach
suggested by Andrey?
This chunk of code isn't all that hard to type or to review, is valid
everywhere (within the context at hand) and, IIUIC, should also be
faster than the C99 version mentioned in the OP:
//-------
PODObject obj;
obj.FunctionValue = MyFunctionImpl;
//-------
And if one really wants a one-liner, one can always take advantage
(grin) of the preprocessor:
//-------
#define CREATEPOD(obj_name, member_name, value) \
PODObject obj_name; \
obj_name.member_name = value;
typedef void(*FunctionType)();
struct PODObject {
void* PointerValue;
FunctionType FunctionValue;
};
void MyFunctionImpl() {}
int main() {
CREATEPOD(obj, FunctionValue, MyFunctionImpl);
obj.FunctionValue();
}
//-------
For the records, I wouldn't use macros, I would just use the two lines I
mentioned first.
--
FSC -
http://userscripts.org/scripts/show/59948
http://fscode.altervista.org -
http://sardinias.com