473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Write a C-program without main() method

please help me..

Yes it is possible to write a program in c without using main.
Here is the code:
Expand|Select|Wrap|Line Numbers
  1. /* prog_without_main.c */
  2. _start()
  3. {
  4. _exit(my_main());
  5. }
  6. int my_main(void)
  7. {
  8. printf(”Hello\n”);
  9. return 42;
  10. }
And use this command (% is command prompt) to compile:
%gcc -O3 -nostartfiles prog_without_main.c
Try compiling this example:
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #define decode(s,t,u,m,p,e,d) m##s##u##t
  3. #define begin decode(a,n,i,m,a,t,e)
  4. void begin()
  5. {
  6. printf(”hello”);
  7. }
here is how it works once we say define we need to understand that
#define x y
then ‘x’ ix replaced by ‘y’
similarly in this case
#define begin decode(a,n,i,m,a,t,e)
decode(a,n,i,m,a,t,e) is replaced by m##a##i##n
bcoz s is replaced by a,t by n,u by i and so on
s->a
t->n
u->i
m->m
p->a
e->t
d->e
now the statement becomes
void m##a##i##n
And u must be knowing that ## is used for string concatenation so it becomes
“main”
finally the code crops down to
Expand|Select|Wrap|Line Numbers
  1. void main()
  2. {
  3. printf(”hello”);
  4. }
Sep 7 '07 #1
4 7026
Nepomuk
3,112 Expert 2GB
please help me..

Yes it is possible to write a program in c without using main.
Here is the code:
...
This most certainly belongs in the C/C++ Forum! ^^

Greetings,
Nepomuk
Sep 7 '07 #2
Purple
404 Expert 256MB
Hi bagkalyan and welcome to TSDN,

As this post is a technical question related to c/c++, I have moved it from the cafe to the appropriate forum.

Take a moment to read the posting guidelines for this site here.

MODERATOR
Sep 7 '07 #3
ilikepython
844 Expert 512MB
please help me..

Yes it is possible to write a program in c without using main.
Here is the code:
/* prog_without_main.c */
_start()
{
_exit(my_main());
}
int my_main(void)
{
printf(”Hello\n”);
return 42;
}
And use this command (% is command prompt) to compile:
%gcc -O3 -nostartfiles prog_without_main.c
Try compiling this example:
#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
void begin()
{
printf(”hello”);
}
here is how it works once we say define we need to understand that
#define x y
then ‘x’ ix replaced by ‘y’
similarly in this case
#define begin decode(a,n,i,m,a,t,e)
decode(a,n,i,m,a,t,e) is replaced by m##a##i##n
bcoz s is replaced by a,t by n,u by i and so on
s->a
t->n
u->i
m->m
p->a
e->t
d->e
now the statement becomes
void m##a##i##n
And u must be knowing that ## is used for string concatenation so it becomes
“main”
finally the code crops down to
void main()
{
printf(”hello”);
}
The second really isn't a program without main. Like you said, it comes to the compiler like:
Expand|Select|Wrap|Line Numbers
  1. void main()
  2. {
  3.  
Anyway, what is your question?
Sep 7 '07 #4
JosAH
11,448 Expert 8TB
The second really isn't a program without main. Like you said, it comes to the compiler like:
Expand|Select|Wrap|Line Numbers
  1. void main()
  2. {
  3.  
Erm, it's "int", not "void". "int"; remember that: int, int, int, intintintintintintint!

kind regards,

Jos ;-)
Sep 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Klaus Neuner | last post by:
Hello, I want to write a class Recognizer, like so: class Recognizer(object): def is_of_category_1(self, token): if token == 1: return "1" else:
5
by: Disiac | last post by:
Hi, MS Class Library Guidelines clearly discourages use of Write-Only properties yet they're continuously availed in .NET after VB 6. Personally, I really don't use them anywhere. Tend to find...
14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
2
by: Eric Mitchell | last post by:
Hello all, I am using the document.write() method to create new content on the same page, however... I need to create a new button using this method (button in HTML). Complicating the matter...
3
by: Gav | last post by:
Hi all, I have created a user control and I am using Response.Write in the control to 'write' exactly what I want although it always goes to the top of the page (above <HTML><HEAD> etc). Can I...
3
by: Farooq Khan | last post by:
why does Response.Write in a method of code-beind class when called from inpage code (i.e in <%---%>), after creating object of that class, fails when called while it works perfectly ok while...
1
by: Phil Sandler | last post by:
Hello all, Thanks in advance for any help with this. I am trying to get sample code to run from Michael Russell's excellent article on removing whitespace:...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
0
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.