LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2010, 03:35 AM   #1
jamesbon
Member
 
Registered: Jun 2010
Posts: 147

Rep: Reputation: 9
what is difference between various symbols of kernel


I was going through some exercise given in my school.I have read the C book but I am not able to understand some part.
That is static variable.
What exactly is a static variable and what does it do?
I saw in Linux Kernel Programming
external and exported are also some thing.
I am not getting the difference between static,EXPORT_SYMBOL,external variable types.
If I make a kernel module then how will I make sure that my variable is visible to the kernel.
Is this what it is all talking about?
I have checked this page
http://en.wikipedia.org/wiki/Static_variable

Last edited by jamesbon; 08-22-2010 at 03:39 AM.
 
Old 08-22-2010, 09:10 AM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You're looking in the right places. However, you probably need some examples.

So, if in my module (to make it simple: one file) I declare a variable and make it static, it'll be available only to code from this file, not from the rest of the kernel. Any other variable will be, but it isn't a good idea to access it directly from the rest of the kernel, because the module may be unloaded at any time.

External is just an indication for the compiler that the variable will be defined somewhere else.

EXPORT_SYMBOL is a macro and may have different meaning, depending on the options. Generally it makes a kernel variable visible from modules. Look how it is defined.
 
Old 08-22-2010, 09:25 AM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
The keyword 'static' has more than one meaning in C, which can lead to confusion.

When you declare a variable static inside a C function, it means that the value will be preserved between function calls, because its storage class is static (typically this means that it is implemented by storing it in a data segment, rather than on the stack).

However, for global variables declared outside a C function, which you would expect to be of a static storage class anyway, it also means that the scope of the variable is limited to the file that contains it. By default, if you do not declare a global variable as static, it will be available to other modules that are linked together with the one that declares the global variable.

The extern declaration on a global variable simply means that the variable is created elsewhere; you have to declare it so that the compiler knows its type, but it is allocated space elsewhere (and it is up to the linker to complete the compilation by inserting the actual address).

Last edited by neonsignal; 08-22-2010 at 09:58 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
'nm' lists all symbols - including static library symbols painulyarun Programming 4 04-06-2010 04:04 AM
Kernel Modules using one another even though not using any symbols vadirajpanch Linux - General 0 10-22-2009 02:07 AM
how to get all symbols of kernel wangjinyi Programming 1 10-19-2005 10:54 PM
kernel: No module symbols loaded - kernel modules not enabled. Qucho Debian 9 05-26-2004 02:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration