[En-Nut-Discussion] Extending device structures, was Re: Problem with STM32 pin ...

Harald Kipp harald.kipp at egnite.de
Tue Oct 13 20:10:38 CEST 2015


Hi Ole,

On 06.10.2015 21:41, Ole Reinhardt wrote:

>> For structure initialization, is there anything against initializing like
>>
>> NUTDEVICE devStm32Lcd16Seg = {
>>     .dev_name = {'1','6', 'S', 'E', 'G', 0, 0, 0},
> 
>> versus the old way:
>>
>> NUTI2C_BUS i2cBus2Stm32 = {
>>     &i2c2cb,    /* bus_icb */
> 
> If you ask ME, I would always vote to use named structure
> initialisation. But keep in mind, that this is C99 standard, not C89.

Well, it's a general decision whether we move from C89 to C99.


> AFAIK he uses some of the Nut/OS code on platforms like the VS10xx DSPs,
> where the compiler only supports C89.

Not really my words. I just liked the fact, that Nut/OS partly compiles
on this exotic compiler. That allowed me to reuse some Nut/OS code.

The main claim was, that a several developers use Microsoft C to
pre-develop Nut/OS applications on Windows first before moving to the
real target. This is very convenient.

But! Using this compiler was possible only because Nut/OS is almost C89
conformant and uses C99 extensions only, if they can be somehow emulated
for C89, like those uintN_t types.

However, there is no chance to tell a C89 compiler to swallow

.dev_name = ...

as a structure element initializer. The code will simply not compile.

If your code is hardware-dependent and if this platform depends on a C99
compiler anyway, then this hardware dependent code may make use of any
special feature, because it is not portable at all. Nobody cares, really.

This is not true for all NUTDEVICES. I developed and tested file system
drivers on Visual Studio 2010, which hardly follows C89, but ignores
almost all C99 goodies.

Well, so far about the history.

Some months ago I moved to VS2013, which claims to support C99. (Who the
hell convinced Microsoft after so many years to put some effort into
their C compiler again?) So, to me it makes not much difference anymore,
whether Nut/OS sticks with C89 or C99. Too me C89 with some C99
polishing is fine, but if you want to give up C89 in your contributions,
I won't bark at it. I may not be able to reuse newer code, but we still
have version 4 branches available.


Regards,

Harald



More information about the En-Nut-Discussion mailing list