Page 1 of 1

[SOLVED] A warning I want to avoid. GCC -Wpedantic

Posted: Tue Jun 24, 2014 8:14 pm
by BASICFreak
After many months of being in the dark without using a cross-compiler I have finally switched to GCC from DJGPP and am now compiling to ELF32-i386 with a MakeFile (yes finally I got a MakeFile)

So after getting all the warning flags set, I ended up having ~3000 warnings to start with went threw tediously fixing all of them, up until I got stuck.

I now have 6 warnings (2 in each of 3 files):
SYSTEM/CPU/INT.c: In function ‘install_INT’:
SYSTEM/CPU/INT.c:21:16: warning: ISO C forbids assignment between function pointer and ‘void *’ [-Wpedantic]
.....IRSs[irq] = handler;
...................^
and the code refereed to is My IRQ ISR and INT handlers (which all are almost identical):

Code: Select all

void *ISRs[32] =
{
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0
};

void install_ISR(uint8_t isr, void (*handler)(regs *r))
{
    ISRs[isr] = handler;
}
void ISR_HANDLER(regs *r)
{
	void (*ISR)(regs *r);
	// Get ISRS Resolve Routine
	ISR = ISRs[r->int_no];
	// Do we have a valid Routine?
	if (ISR)
		ISR(r);
	else
		iError(r);	// No Routine BSoD time.
}
I have tried a few ways that did remove the warning, but unfortunately makes the code inoperable.

Anyone have any suggestions of how to avoid this?

Thanks
- Brian

Re: A warning I want to avoid. GCC -Wpedantic

Posted: Tue Jun 24, 2014 8:57 pm
by alexfru
Try a proper declaration:
void (*ISRs[32])(regs*);

Re: A warning I want to avoid. GCC -Wpedantic

Posted: Tue Jun 24, 2014 9:47 pm
by bluemoon
A more readable form:

Code: Select all

typedef void (*ISR_HANDLER)(regs*);
ISR_HANDLER ISRs[32] = {0}; // Note that single zero tell the compiler fills the entire array

void install_ISR(uint8_t isr, ISR_HANDLER handler) {
    // TODO: range check!
    ISRs[isr] = handler;
}


Re: A warning I want to avoid. GCC -Wpedantic

Posted: Tue Jun 24, 2014 9:51 pm
by alexfru
You don't need to provide explicit initializers for static variables, if 0/NULL/0.0 is all you want.

Re: A warning I want to avoid. GCC -Wpedantic

Posted: Tue Jun 24, 2014 9:55 pm
by bluemoon
alexfru wrote:You don't need to provide explicit initializers for static variables, if 0/NULL/0.0 is all you want.
Yes it's not needed, BSS should be zero'd anyway.
But for readability that you may explicitly tell the compiler & programmers you want zeros just to be sure.

Re: A warning I want to avoid. GCC -Wpedantic

Posted: Wed Jun 25, 2014 12:14 am
by BASICFreak
Thanks all you for the quick replies.

Well, the least I can say is now I know... Should have seen that one though...

again Thanks
- Brian