GCC4 and io.h
GCC4 and io.h
Hi,
i tried to compile my os with gcc 4.1 but it prompts me errors.
error: invalid storage class for function 'outb'
header file:
static inline void outb( unsigned short port, unsigned char value ) {
asm volatile( "outb %%al, %%dx" : : "a"(value),"d"(port));
}
thats because gcc 4 doesnt support nested functions (routines declared as static routines in another routine).
so how can i fix this error without moving the .h code to .c?
thanks for your help
i tried to compile my os with gcc 4.1 but it prompts me errors.
error: invalid storage class for function 'outb'
header file:
static inline void outb( unsigned short port, unsigned char value ) {
asm volatile( "outb %%al, %%dx" : : "a"(value),"d"(port));
}
thats because gcc 4 doesnt support nested functions (routines declared as static routines in another routine).
so how can i fix this error without moving the .h code to .c?
thanks for your help
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GCC4 and io.h
i'd be checking whether there's a missing ";" in the previous command, if i were you... there's no need for "nesting" here, right? all you need (beside love ) is to have the inline function defined at top-level ...
or am i missing something in your intent?
or am i missing something in your intent?
Re:GCC4 and io.h
Inline implies it shouldn't be output. What does the static do there?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GCC4 and io.h
that 's a typical gcc-stuff: if you say "void f(...) {...}" you give GCC a function it may inline it if it feels like, or it may not. If you say "inline void f(...) {...}" you actually request GCC to make sure every instance of the function call is inlined. Though there might be odd cases where the standalone code of the function is still required (e.g. you might have a function pointer or an external unit calling it).Candy wrote: Inline implies it shouldn't be output. What does the static do there?
With inline functions in .h files, that'd mean a useless version of the standalone function would exist in every .o, so you use "static inline" to instruct GCC that noone from outside of this unit can call that code. If you don't extract the address of the function either, GCC can now handle the function as a "pure" inline one.
With strong optimization, "static" is actually enough for most functions ...
Re:GCC4 and io.h
Isn't whether it outputs anything controlled by a compile-time switch? I recall seeing something like that some time ago...Pype.Clicker wrote: With inline functions in .h files, that'd mean a useless version of the standalone function would exist in every .o, so you use "static inline" to instruct GCC that noone from outside of this unit can call that code. If you don't extract the address of the function either, GCC can now handle the function as a "pure" inline one.
Re:GCC4 and io.h
the code compiles fine with gcc 3.x.x, and the above error message has been intruduced with gcc 4.0. as the function itself will be included into the calling routine with static inline... removing the static fixes this issue but of course errors about multiply definition too.
as i mentioned gcc 4.0 doesnt like inner routines defined by static. any solutions?
as i mentioned gcc 4.0 doesnt like inner routines defined by static. any solutions?
Re:GCC4 and io.h
Why is it an inner routine? ??? outb should be defined at file-level (not inside another function). (You should #include "io.h" at the top of the .c file.)darksun wrote: as i mentioned gcc 4.0 doesnt like inner routines defined by static.
Re:GCC4 and io.h
yes sorry. its too late for me, of course it will be included at the top of the .c file. the only important part is that gcc 4 does not like static inline anymore. so one solution would be to put it in a .c itself, but i would be happier to see it in a .h file. is it possible with the version4?
Re:GCC4 and io.h
I'm using static inline functions and GCC 4 compiles them, so I don't think that can be the problem...
But I don't understand why outb is a nested function, instead of just a normal function. Can you run gcc -E whatever_the_name_of_your_c_file_is.c and post the part near the definition of outb?
P.S. Don't forget that #include just inserts the contents of the .h file into the .c file, so anything you can put into a .c file you can put into an .h file.
But I don't understand why outb is a nested function, instead of just a normal function. Can you run gcc -E whatever_the_name_of_your_c_file_is.c and post the part near the definition of outb?
P.S. Don't forget that #include just inserts the contents of the .h file into the .c file, so anything you can put into a .c file you can put into an .h file.
Re:GCC4 and io.h
thanks for the suggestion of using gcc -E, it shows a recursive error. everything is fixed. thanks alot, just because of the error message and the available fixes on the net it leads me to the wrong direction. again, thanks for your help