Computer Science Canada Question about macro __init |
Author: | Geminias [ Wed Aug 08, 2007 6:44 am ] | ||||
Post subject: | Question about macro __init | ||||
Please clear up what __init exactly is and how it works. It is described as: The __init macro causes the init function to be discarded and its memory freed once the init function finishes for built-in drivers, but not loadable modules. Which I perfectly understand but do not understand how it works. I looked it up in init.h only to become more confused. I found this:
I'm mainly interested in __init because I've never seen syntax like: storage_class return_type macro function() I also I don't really know what static does. I think it is different from the C++ static keyword... right?
|
Author: | OneOffDriveByPoster [ Thu Aug 09, 2007 9:39 am ] |
Post subject: | Re: Question about macro __init |
Geminias @ Wed Aug 08, 2007 6:44 am wrote: I'm mainly interested in __init because I've never seen syntax like:
Nothing special... the macro could have been an obfuscated part of the return type like "unsigned". What you probably want to know if what the GNU extension for function attributes is. __attribute__((__section__(".init.text") )) causes the function to go into a special section of the compiled object. The linker puts it into some (I guess special) segment, and the loader does something special with it so that you get the behaviour you described. So go hunt down what .init.text is.
storage_class return_type macro function() Quote: I also I don't really know what static does. I think it is different from the C++ static keyword... right? Well, C++ lets you use "static" this way too. It makes it so that the function can only be referenced by name in this source file. Other source files can have functions of the same name, but they won't be this function. It affects the linkage of the function. |
Author: | Geminias [ Fri Aug 10, 2007 5:34 am ] |
Post subject: | Re: Question about macro __init |
But C++ adds a new definition to static for when you use it as a member variable of a class. I believe in this case it means the variable can be used without creating an object of that class. Since C doesn't support classes I am guessing this has no relevance in C. Aside from that, thanks for clarifiying __attribute__, I just realized that I actually knew what it was from a previous encounter that just unrooted itself in my brain as I read your comment. |