Page 1 of 1
GCC4 and io.h
Posted: Tue Sep 05, 2006 9:53 am
by darksun
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
Re:GCC4 and io.h
Posted: Tue Sep 05, 2006 10:34 am
by Pype.Clicker
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?
Re:GCC4 and io.h
Posted: Tue Sep 05, 2006 12:15 pm
by Candy
Inline implies it shouldn't be output. What does the static do there?
Re:GCC4 and io.h
Posted: Tue Sep 05, 2006 12:34 pm
by Pype.Clicker
Candy wrote:
Inline implies it shouldn't be output. What does the static do there?
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).
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
Posted: Tue Sep 05, 2006 12:52 pm
by Candy
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.
Isn't whether it outputs anything controlled by a compile-time switch? I recall seeing something like that some time ago...
Re:GCC4 and io.h
Posted: Tue Sep 05, 2006 2:59 pm
by darksun
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?
Re:GCC4 and io.h
Posted: Tue Sep 05, 2006 3:56 pm
by nick8325
darksun wrote:
as i mentioned gcc 4.0 doesnt like inner routines defined by static.
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.)
Re:GCC4 and io.h
Posted: Tue Sep 05, 2006 4:02 pm
by darksun
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
Posted: Tue Sep 05, 2006 4:10 pm
by nick8325
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.
Re:GCC4 and io.h
Posted: Tue Sep 05, 2006 4:51 pm
by darksun
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