The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How ls | wc -l works? krishmaths UNIX for Dummies Questions & Answers 3 04-11-2008 01:16 PM
Help it works but its to SLOW Garlandxj Shell Programming and Scripting 10 04-03-2008 12:17 AM
Works with FTP but not NFS pbonilla UNIX for Dummies Questions & Answers 1 01-08-2008 02:31 PM
how domain name reg works vutty81 IP Networking 4 11-20-2007 03:00 PM
Code works sometimes and sometimes not hp-aix-lnx-user Shell Programming and Scripting 2 04-06-2006 08:43 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-25-2008
amit4g's Avatar
Registered User
 

Join Date: Apr 2006
Location: Bangalore,India
Posts: 29
How does NORET_TYPE works ?

Hi,

I was looking at the panic() code in linux kernel which is defined as:
51 /**
52 * panic - halt the system
53 * @fmt: The text string to print
54 *
55 * Display a message, then perform cleanups.
56 *
57 * This function never returns.
58 */
59
60 NORET_TYPE void panic(const char * fmt, ...)

where, NORET_TYPE is declared as
/*
753 * Ok, these declarations are also in <linux/kernel.h> but none of the
754 * ext3 source programs needs to include it so they are duplicated here.
755 */

# define NORET_TYPE /**/ <====

Please help me in understanding a #defined variable(NORET_TYPE here) which is not defined to anything.
I know that panic() function was designed in this way to not to return anything{in case of panic,there won't be anyone to catch the return value from panic() },but how does this work.
i think a program in user land having a #defined variable which is left blank will throw compile time error.how this is implemented in linux kernel ?
I don't know much about C,hence please excuse me if this is a stupid querry .

~amit
Reply With Quote
Forum Sponsor
  #2  
Old 01-28-2008
amit4g's Avatar
Registered User
 

Join Date: Apr 2006
Location: Bangalore,India
Posts: 29
Thumbs up

[amit@venus]$ cat temp.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define MYVAR
MYVAR int main(void){
printf("success\n");
exit(EXIT_SUCCESS);
}

[amit@venus]$ gcc -o temp -S temp.c

[amit@venus]$ cat temp_wo_macro.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define MYVAR
int main(void){ <===
printf("success\n");
exit(EXIT_SUCCESS);
}
[amit@venus]$ gcc -o temp_wo_macro -S temp_wo_macro.c
[amit@venus]$ diff temp temp_wo_macro
1c1
< .file "temp.c"
---
> .file "temp_wo_macro.c"

I really don't know, that why i didn't tried this small exercise before,
anyways as Bill pointed,it seems that it is perfectly legal to have a #defined variable left blank,
though if you try to access the same variable you need to assign it first.

here the code just gets expanded as "int main(void)"
They might have added this MACRO(NORET_TYPE) just to make sure that
nobody replaces ' void ' with anything else.


~amit
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0