I am experiencing many issues with SDCC when choose it as compiler on z88dk, the SmallC compiler seems much more robust and smarter for writing code. I.e. with SmallC I can define a fixed address directly as pointer:
#define g_myvar ((MyStruct*)*(void*)0xAAAA)
As use it directly as a pointer variable:
g_myvar = malloc(); ... g_myvar->member = ...
This doesn't work on SDCC, and must be changed to:
#define g_myvar_address (uint16_t*)0xAAAA #define g_myvar ((MyStruct*)g_myvar_address)
And then cannot use directly to update the address, has to use it separately:
*g_myvar_address = malloc(); ... g_myvar->member = ...
This works without errors or warnings:
MyStruct* __at (0xAAAA) g_myvar = malloc(some_value); ... g_myvar->member = ...
But I found your syntax confusing. If I were to write it all in a single macro, I would use:
#pragma disable_warning 88 // disable warning about casting literal value to pointer #define g_myvar (*((MyStruct**)0xAAAA)) g_myvar = malloc(); ... g_myvar->member = ...
I don't think even gcc or clang accept that macro syntax from your sample code.
SmallC does. Also it means "use as struct pointer what is at address", as the casting is made right-to-left, I see it less confusing than a double pointer with a * at top left, as I want to get clear that is a struct pointer, instead the data at (typical of a * at left). Notice that I don't even need to force a disable warning, so I see it more intuitive.
If the double pointer was enough then fine, but at the moment I see a * at left, don't like.
Specific extensions is better to avoid.
I don't think it's about intuitiveness, warnings came later on with standardisation to tell the user that they could be potentially shooting themselves on the foot. But, in a dialect that is common enough in resource-limited computing and low-level programming, we disable it just to suppress the message.
Specific extensions is better to avoid.
With the standardisation of C, I think that the cast you used is considered the "extension" today since most C compilers in ANSI-C mode would complain.
Then splitting is better than using an exclusive extension. This said without trying to check if is or not compliant.