Execute fuction not called directly or indirectly by main
Page 1 of 1
Execute fuction not called directly or indirectly by main
Help me in writing a simple c library
My friend is learning C and require the Hello World program
so I wrote a hello world program but instead of writing
#include<stdio.h>
int main()
{
printf("hello world");
}
I wrote
#include<stdio.h>
int main()
{
}
Now i have sent it to my friend and I don't want that he found the error so
I convince him that it require a library to compile and print correctly .
Help me writing my library
My friend is learning C and require the Hello World program
so I wrote a hello world program but instead of writing
#include<stdio.h>
int main()
{
printf("hello world");
}
I wrote
#include<stdio.h>
int main()
{
}
Now i have sent it to my friend and I don't want that he found the error so
I convince him that it require a library to compile and print correctly .
Help me writing my library
arahan- Posts : 4
Join date : 2008-10-14
Hint
You have to Create a function which is called automatically after main without calling and compile with the original source code .
Use Function Attribute to create such a function.
Use Function Attribute to create such a function.
arahan- Posts : 4
Join date : 2008-10-14
The solution for the problem
Here we are using function attribute : destructor to create a function that will be executed after main.
#include<stdio.h>
void CorrectOutput(void ) __attribute__ ((destructor));
void CorrectOutput(void)
{
printf("Hello World");
}
compile this file along with the main file
and execute
OUTPUT:
Hello World
#include<stdio.h>
void CorrectOutput(void ) __attribute__ ((destructor));
void CorrectOutput(void)
{
printf("Hello World");
}
compile this file along with the main file
and execute
OUTPUT:
Hello World
arahan- Posts : 4
Join date : 2008-10-14
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum