Re: How does NORET_TYPE works ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[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 i guess 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.

Thanks Mulyadi for throwing the light here.

~amit

On Jan 25, 2008 5:50 PM, Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:
Hi...

On Jan 25, 2008 6:59 PM, amit mehta <amit4g@xxxxxxxxx> wrote:
>  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 about it either, but try to create simple C program that
mimic this situation i.e make no_ret void func. Then call it from
main(). Don't do any optimization (-O0). Simply stop at assembling
stage (gcc -S) and see the .S file as the result. Perhaps you can
understand it better by your own from here.


>  I don't know much about C,hence please excuse me if this is a stupid querry

There's no such stupid query. The real stupidity is when you know you
are stupid but have no courage to study.

regards,

Mulyadi.


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux