473,748 Members | 6,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write a C-program without main() method

1 New Member
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_ma in.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 7059
Nepomuk
3,112 Recognized Expert Specialist
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 Recognized Expert Contributor
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 Recognized Expert Contributor
please help me..

Yes it is possible to write a program in c without using main.
Here is the code:
/* prog_without_ma in.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_ma in.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 Recognized Expert MVP
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, intintintintint intint!

kind regards,

Jos ;-)
Sep 7 '07 #5

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

Similar topics

5
1486
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
3893
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 it as giving the 'highest' possible access to data as compared to a plain read. However, out of more than a passing interest, does anyone know of a clear cut reason why developers are clearly discouraged from using Write-Only properties?
14
4124
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 it's being written into the page. Is there a way that I can view what is being placed into the page, instead of, or in addition to the javascript code?
2
2935
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 worse, I have a javascript function that needs to be called in the onClick event of the button. Is there any way of doing this? Here is my code, which gives me an error because the function is read as an object, and there is no object... <script...
3
6278
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 get it so that it writes it where the control is on the page? ie <html>
3
1700
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 calling the same method same way except for creating object instead directly calling the method? i get this when trying to do that:- ************************************************** Response is not available in this context. Description: An...
1
7510
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: http://www.codeproject.com/aspnet/WhitespaceFilter.asp I have also tried his updated version, which can be found (in a zip file) here:
0
789
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 by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
14054
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 by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
0
3867
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 string. write method should take a string. seek should take a number and return nuthing. use three member variables a buffer itself as a string, read_position, write_position. use >>, << methods. I have tried this code but i need full...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.