Computer Club MNNIT
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Execute fuction not called directly or indirectly by main

Go down

Execute fuction not called directly or indirectly by main Empty Execute fuction not called directly or indirectly by main

Post  arahan Wed Oct 15, 2008 8:04 am

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 Exclamation Exclamation Exclamation

arahan

Posts : 4
Join date : 2008-10-14

Back to top Go down

Execute fuction not called directly or indirectly by main Empty Hint

Post  arahan Sat Nov 08, 2008 1:28 am

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.

arahan

Posts : 4
Join date : 2008-10-14

Back to top Go down

Execute fuction not called directly or indirectly by main Empty The solution for the problem

Post  arahan Sun Nov 09, 2008 1:26 am

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

arahan

Posts : 4
Join date : 2008-10-14

Back to top Go down

Execute fuction not called directly or indirectly by main Empty Re: Execute fuction not called directly or indirectly by main

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum