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_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”);
-
}
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
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
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:
Anyway, what is your question?
JosAH 11,448
Recognized Expert MVP
The second really isn't a program without main. Like you said, it comes to the compiler like:
Erm, it's "int", not "void". "int"; remember that: int, int, int, intintintintint intint!
kind regards,
Jos ;-)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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?
|
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?
|
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...
|
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>
| |
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...
|
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:
|
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
|
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
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |