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

Programming, for all ages and all languages.
Post Reply
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

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

Post 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
Last edited by BASICFreak on Wed Jun 25, 2014 12:18 am, edited 1 time in total.
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

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

Post by alexfru »

Try a proper declaration:
void (*ISRs[32])(regs*);
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

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

Post 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;
}

alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

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

Post by alexfru »

You don't need to provide explicit initializers for static variables, if 0/NULL/0.0 is all you want.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

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

Post 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.
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

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

Post 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
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
Post Reply