LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-13-2010, 02:21 AM   #1
ravishekhar.82
Member
 
Registered: Feb 2010
Posts: 30

Rep: Reputation: 15
Question #if defined(__cplusplus) in Kernel


Hi,

In places there are statement like ...
#if defined(__cplusplus)
//do something.

For example, in include/linux/stddef.h ,

Code:
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif
What this statement is doing here and what is the significance of having it. Please explain.

Last edited by ravishekhar.82; 04-13-2010 at 02:23 AM.
 
Old 04-13-2010, 02:24 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
See if the below link helps you !
http://developers.sun.com/solaris/ar...l_linkage.html
 
Old 04-13-2010, 02:37 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
So I am curious ravi as to how many times and in how many different ways you are going to ask how #define works in C++???

Also, do you not have access to any search engines? Simply pasting in __cplusplus in google has over 200K hits and if you are
really as capable as you have said with C I cannot for the life of me workout why you are unable to get / understand this information.
 
Old 04-13-2010, 03:37 AM   #4
ravishekhar.82
Member
 
Registered: Feb 2010
Posts: 30

Original Poster
Rep: Reputation: 15
Quote:
So I am curious ravi as to how many times and in how many different ways you are going to ask how #define works in C++???
Hi,

I know what is the meaning of the statement and #define works in C or C++.

I think I have to clarify my question bit more.

Quote:
What this statement is doing here and what is the significance of having it. Please explain
Basically as we all know Kernel code is compiled with gcc not and not having support for C++, then why C++ preprocessor thing is present here.

My guess is that there must be some strong reason for it. I wanted to know that ???

And I again what to say that I am learning internals of kernel and trying to find out why thing are done the way it is.
I approached the way to learn by directly looking into code itself.

Last edited by ravishekhar.82; 04-13-2010 at 03:40 AM.
 
Old 04-13-2010, 07:19 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Quote:
Basically as we all know Kernel code is compiled with gcc not and not having support for C++
This is an inaccurate statement. There is nothing to say that a C++ program cannot include headers that are also used
in the compilation of the kernel.
However, what we are saying is that if you choose to take portions of particular files, as you have been doing, that not all
pieces are immediately transferable.

Point in case, if you took only part of the code you have highlighted:
Quote:
#define NULL ((void *)0)
And place this in your C++ code it may more than likely fail as C++ does not support this construct in this way,
hence why the reference to:
Quote:
#if defined(__cplusplus)
So now this particular set of code is portable to both C and C++

Quote:
And I again what to say that I am learning internals of kernel and trying to find out why thing are done the way it is.
I approached the way to learn by directly looking into code itself.
And again I would say, you need to go and do a course (online or otherwise) as you have really asked very similar
questions about the exact same topic several times.

Last edited by grail; 04-13-2010 at 07:21 AM.
 
  


Reply

Tags
kernel, linux



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
How to use functions defined inside the kernel source rico1505 Linux - Kernel 2 02-10-2010 01:20 PM
how to insert a module in kernel through a user defined service sharad Linux - General 5 03-25-2007 11:46 PM
How to access 2.6 kernel macros defined under __KERNEL__ someshwar Linux - Kernel 2 10-31-2006 11:36 PM
user defined function in kernel vishalbutte Programming 4 02-07-2006 06:01 AM
kernel boot prameters - where defined? enlight1 Linux - Newbie 2 12-24-2003 12:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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