473,395 Members | 1,678 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,395 software developers and data experts.

How can to write a c program without a main()

How can to write a c program without a main()
so i can compile and run it

Nov 23 '05 #1
37 2354
"Spidey" <am********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
How can to write a c program without a main()
so i can compile and run it

If you are able to write and run such a program,
it, by definition, is not a C program.

-Mike
Nov 23 '05 #2
"Spidey" <am********@gmail.com> writes:
How can to write a c program without a main()
so i can compile and run it


Some systems, particularly embedded systems, may not require a main()
function. (I think some Windows implementations may use something
like "WinMain".) Conforming hosted implementations always require
main().

Why do you want to do this? It seems like another "How do I drive
nails without using a hammer?" question.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 23 '05 #3
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
"Spidey" <am********@gmail.com> writes:
How can to write a c program without a main()
so i can compile and run it
Some systems, particularly embedded systems, may not require a main()
function. (I think some Windows implementations may use something
like "WinMain".) Conforming hosted implementations always require
main().


Some compilers and/or linkers have options to designate alternate
entry points -- which would be system specific (and thus non-portable).
Even systems that provide such mechanisms might only allow limited
functionality -- for example, potentially if main() is skipped, then
I/O might not be initialized, or the environment variables might
not be set up properly. Tis thus very much a "use at your own risk"
feature that is outside the boundaries of the C language.
--
Prototypes are supertypes of their clones. -- maplesoft
Nov 23 '05 #4
Though it is idiotic but try this .....:):):):):):):):):)
#define A main(){
A
printf("hello\n");
}

Nov 23 '05 #5

"Joel" <sa*****************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Though it is idiotic but try this .....:):):):):):):):):)
#define A main(){
A
printf("hello\n");
}


OP asked about a program *without* a 'main()'
function. The above has one. However the
program has undefined behavior due to the
call to 'printf()' with no prototype in scope.

Also note that it doesn't conform to C99, which
requires a return type of 'int'.

-Mike
Nov 23 '05 #6
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
"Spidey" <am********@gmail.com> writes:
How can to write a c program without a main()
so i can compile and run it
Some systems, particularly embedded systems, may not require a main()
function.


Yes. I used an embedded devel system where explicitly declaring the entry
point (it could be "main" if you wanted, but usually wasn't) would eliminate
the initialization code. You didn't get zeroed globals, I/O had to be
initialized by the code, if you wanted to use it, the stack was undeclared,
couldn't return from that code or use exit(), and so on. You needed to either
set up the stack very early (like, first line) with an asm( ) statement, or the
entry could be assembly code. I recall a warning at the top of the page which
outlined was would NOT be done that said something like "If you don't
understand all this, don't do it".
Why do you want to do this? It seems like another "How do I drive
nails without using a hammer?" question.


Nice turn of a phrase there.

- Bill
Nov 23 '05 #7
neo
dear spidey,

there are always rules for the game otherwise things won't go work . C
language has only way as an entry point for a program is main()
function in DOS environment and WinMain () function in Windows
environment.

To my knowledge all C compilers are need to follow this standard, well
you search for some alternative and let me know if you find an answer

Take Care
neo

Nov 23 '05 #8
Spidey wrote:

How can to write a c program without a main()
so i can compile and run it


A function named "main"
Is the one and only thing
A C program needs

--
pete
Nov 23 '05 #9
Mike Wahler <mk******@mkwahler.net> wrote:
"Joel" <sa*****************@gmail.com> wrote in message
#define A main(){
A
printf("hello\n");
}

Also note that it doesn't conform to C99, which
requires a return type of 'int'.


Since we're in pedantry mode, it also returns an undefined termination
status to the host environment in C89.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 23 '05 #10
neo wrote
(in article
<11*********************@f14g2000cwb.googlegroups. com>):
dear spidey,

there are always rules for the game otherwise things won't go work . C
language has only way as an entry point for a program is main()
function in DOS environment and WinMain () function in Windows
environment.


Do really think C gets is use of main() from DOS? Or are DOS
and Windows the only two platforms you are aware of being used
for C programming?
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Nov 23 '05 #11

"Spidey" <am********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
How can to write a c program without a main()
so i can compile and run it


Link against a(ny) library (such as cgic) which defines the main function
for you.
Nov 23 '05 #12
pete said:
Spidey wrote:

How can to write a c program without a main()
so i can compile and run it


A function named "main"
Is the one and only thing
A C program needs


Please do not forget
The implementation's role
Sine qua non C.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 23 '05 #13
In article <ZU***************@monger.newsread.com>,
Mark B <so***@localbar.com> wrote:

"Spidey" <am********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googleg roups.com...
How can to write a c program without a main()
so i can compile and run it


Link against a(ny) library (such as cgic) which defines the main function
for you.


Or, to put it another way, write a shared library (off topic here, of
course), that is loaded by an existing piece of software that you did not
write.

Lawyers can debate whether this constitutes "writing a program", but for
the rest of us, it's good enough.

Nov 23 '05 #14

"neo" <pa**********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
dear spidey,

there are always rules for the game otherwise things won't go work . C
language has only way as an entry point for a program is main()
function in DOS environment and WinMain () function in Windows
environment.
Really? I write quite a few C programs with entry point
'main()' in a Windows environment.

Whether the host environment is DOS, Windows, or something
else, has no bearing at all on the C entry point function's
name.
To my knowledge all C compilers are need to follow this standard,


Those for hosted implementations claiming conformance must
require one entry point function name: 'main'.

-Mike
Nov 23 '05 #15
Spidey wrote:
How can to write a c program without a main()
so i can compile and run it

Maybe the OP wants to compile a module.
you can have modules without main().
gcc -c module.c
produces just the .o (object) file required for linking.

Regards,
Frodo Baggins

Nov 23 '05 #16
"Mike Wahler" <mk******@mkwahler.net> writes:
"neo" <pa**********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
dear spidey,

there are always rules for the game otherwise things won't go work . C
language has only way as an entry point for a program is main()
function in DOS environment and WinMain () function in Windows
environment.


Really? I write quite a few C programs with entry point
'main()' in a Windows environment.

Whether the host environment is DOS, Windows, or something
else, has no bearing at all on the C entry point function's
name.


That's true for conforming hosted implementations. I think that some
of the popular implementations under Windows don't qualify, at least
in some modes.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 23 '05 #17
"Frodo Baggins" <fr*********@gmail.com> writes:
Spidey wrote:
How can to write a c program without a main()
so i can compile and run it


Maybe the OP wants to compile a module.
you can have modules without main().
gcc -c module.c
produces just the .o (object) file required for linking.


Yes, but the OP specifically asked how to compile *and run* a
*program*.

There's no point in guessing what he meant. If he cares, he can come
back and explain. If he doesn't, neither do I.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 23 '05 #18
pete wrote:
Spidey wrote:

How can to write a c program without a main()
so i can compile and run it


A function named "main"
Is the one and only thing
A C program needs


Understandable,
notwithstanding freestanding
implementations.

Nov 23 '05 #19
Old Wolf wrote:
pete wrote:

Spidey wrote:
How can to write a c program without a main()
so i can compile and run it


A function named "main"
Is the one and only thing
A C program needs

Understandable,
notwithstanding freestanding
implementations.


Forget the Obfuscated C Contest, we need a C Haiku Contest.

S.
Nov 23 '05 #20


Spidey wrote:
How can to write a c program without a main()
so i can compile and run it


Simply edit the startup code.
which is of course WOT.
Nov 24 '05 #21
Skarmander <in*****@dontmailme.com> wrote:
Old Wolf wrote:
pete wrote:
Spidey wrote:

How can to write a c program without a main()
so i can compile and run it

A function named "main"
Is the one and only thing
A C program needs


Understandable,
notwithstanding freestanding
implementations.


Forget the Obfuscated C Contest, we need a C Haiku Contest.


Senryu. Or zappai. Not haiku.

Richard
Nov 24 '05 #22
Richard Bos said:
Skarmander <in*****@dontmailme.com> wrote:
Old Wolf wrote:
> pete wrote:
>
>>Spidey wrote:
>>
>>>How can to write a c program without a main()
>>>so i can compile and run it
>>
>>A function named "main"
>>Is the one and only thing
>>A C program needs
>
> Understandable,
> notwithstanding freestanding
> implementations.


Forget the Obfuscated C Contest, we need a C Haiku Contest.


Senryu. Or zappai. Not haiku.


In this C newsgroup,
Haiku is as haiku does;
This is normative.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 24 '05 #23
Well you need to ask this question at gcc newsgroup. The only way to do
this is to modify compiler and libraries. YOu need to tinker with
__main, crt0 or crt1.

regards
VK

Nov 24 '05 #24
On 2005-11-24, hi***********@gmail.com <hi***********@gmail.com> wrote:
Well you need to ask this question at gcc newsgroup. The only way to do
this is to modify compiler and libraries. YOu need to tinker with
__main, crt0 or crt1.


__main? I think you mean _start

[which is, of course, off-topic for this newsgroup]
Nov 24 '05 #25
In article <sl********************@random.yi.org>,
Jordan Abel <jm****@purdue.edu> wrote:
On 2005-11-24, hi***********@gmail.com <hi***********@gmail.com> wrote:
Well you need to ask this question at gcc newsgroup. The only way to do
this is to modify compiler and libraries. YOu need to tinker with
__main, crt0 or crt1.


__main? I think you mean _start

[which is, of course, off-topic for this newsgroup]


As is anything else that is the least bit interesting.

(And you know I'm right. Go ahead and deny it, but you know I'm right)

Nov 24 '05 #26
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):
[which is, of course, off-topic for this newsgroup]


As is anything else that is the least bit interesting.


Feel free to unsubscribe if you find clc boring. please.

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Nov 24 '05 #27
In article <00*****************************@news.verizon.net> ,
Randy Howard <ra*********@FOOverizonBAR.net> wrote:
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):
[which is, of course, off-topic for this newsgroup]


As is anything else that is the least bit interesting.


Feel free to unsubscribe if you find clc boring. please.


What give ya dat idea?

Since just about everything here is O/T, it's not boring.

Nov 24 '05 #28
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):
In article <00*****************************@news.verizon.net> ,
Randy Howard <ra*********@FOOverizonBAR.net> wrote:
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):
[which is, of course, off-topic for this newsgroup]

As is anything else that is the least bit interesting.


Feel free to unsubscribe if you find clc boring. please.


What give ya dat idea?


You saying it, probably.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Nov 24 '05 #29
Randy Howard said:
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):
In article <00*****************************@news.verizon.net> ,
Randy Howard <ra*********@FOOverizonBAR.net> wrote:
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):

> [which is, of course, off-topic for this newsgroup]

As is anything else that is the least bit interesting.

Feel free to unsubscribe if you find clc boring. please.


What give ya dat idea?


You saying it, probably.


Given his track record, what makes you think he was correct?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 24 '05 #30
In article <dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Randy Howard said:
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):
In article <00*****************************@news.verizon.net> ,
Randy Howard <ra*********@FOOverizonBAR.net> wrote:
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):

>> [which is, of course, off-topic for this newsgroup]
>
> As is anything else that is the least bit interesting.

Feel free to unsubscribe if you find clc boring. please.

What give ya dat idea?


You saying it, probably.


Given his track record, what makes you think he was correct?


You guys really are pathetic.

Although I shouldn't have to point this out, the part that you (both)
deleted explained exactly why CLC is anything but boring.

Nov 24 '05 #31
Kenny McCormack wrote:
In article <dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Randy Howard said:

Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):
In article <00*****************************@news.verizon.net> ,
Randy Howard <ra*********@FOOverizonBAR.net> wrote:

>Kenny McCormack wrote
>(in article <dm**********@yin.interaccess.com>):
>
>
>>>[which is, of course, off-topic for this newsgroup]
>>
>>As is anything else that is the least bit interesting.
>
>Feel free to unsubscribe if you find clc boring. please.

What give ya dat idea?

You saying it, probably.


Given his track record, what makes you think he was correct?

You guys really are pathetic.

Although I shouldn't have to point this out, the part that you (both)
deleted explained exactly why CLC is anything but boring.

Hi Kenny,

You don't seem to get it. Us 'guys' are not pathetic and if you think we
are, who cares what you think? And we don't take ourselves too seriously
most of the time. We tend to take the group comp.lang.c seriously
though. We respect the group and we expect you to. If you cannot, please
go away.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 24 '05 #32
Joe Wright <jw*****@comcast.net> writes:
Kenny McCormack wrote: [snip] Hi Kenny,

You don't seem to get it. Us 'guys' are not pathetic and if you think
we are, who cares what you think? And we don't take ourselves too
seriously most of the time. We tend to take the group comp.lang.c
seriously though. We respect the group and we expect you to. If you
cannot, please go away.


Gentlemen, you're giving him exactly what he wants: attention. KM has
shown repeatedly that he will not listen to advice, polite requests,
insults, or anything else. He will continue to be a troll, and he
will continue to try to disrupt this newsgroup.

I suggest that the newsgroup will be better of if we all ignore him.
If you use a killfile, add him to it. If you don't, resist the
temptation to engage him in conversation.

This will mean letting him have the last word. That doesn't imply
agreement, merely that he's not worth responding to.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 24 '05 #33
neo
What U really mean
Do U mean that U can change entry point for C program from main ()
function to some else.
If U can then tell me how?

Nov 25 '05 #34
Randy Howard <ra*********@FOOverizonBAR.net> wrote:
Kenny McCormack wrote
(in article <dm**********@yin.interaccess.com>):
[which is, of course, off-topic for this newsgroup]


As is anything else that is the least bit interesting.


Feel free to unsubscribe if you find clc boring. please.


Ah, but he doesn't. Regardless of topicality, he can still abuse c.l.c
to discuss the topic that will always be the only one that truly
interests him: himself.

Richard
Nov 25 '05 #35
void main()

Dec 5 '05 #36
re********@hotmail.com wrote:

void main()


That's not a C program.

--
pete
Dec 6 '05 #37
re********@hotmail.com writes:
void main()


Please watch your language. 8-)}

Seriously, I can't see the message to which you're replying. If that
was meant to be a reply to the question in the subject, it's wrong for
at least two reasons.

Please <http://cfaj.freeshell.org/google/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 6 '05 #38

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: gswork | last post by:
Let's write a c program, without knowing what it does... Some of you may recall Jim Roger's excellent series of posts (on comp.programming) exploring the implementation of common software...
22
by: Saurabh Saxena | last post by:
can we write the program to write no 1 to n without using switch,do,while,for,goto,if and conditional operator where n will be input by user.
16
by: Puneet | last post by:
Hi ALL, I have a silly question... (may be) Can we write a single line C program whose output is the program itself? Is anybody know the answer please tell me. Puneet
26
by: Martin Jørgensen | last post by:
Hi, I'm learning C-programming. I have a program which I would like to modify so it takes arguments from the commandline. Let call the program: program.exe. Could somebody shortly explain how...
27
by: lovecreatesbea... | last post by:
This code snippet is an exercise on allocating two dimension array dynamically. Though this one is trivial, is it a correct one? Furthermore, when I tried to make these changes to the original...
6
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
4
by: bagkalyan | last post by:
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)
63
by: Bill Cunningham | last post by:
I don't think I can do this without some help or hints. Here is the code I have. #include <stdio.h> #include <stdlib.h> double input(double input) { int count=0,div=0; double...
11
by: 960392954 | last post by:
The Towers of Hanoi is a famous problem about moving a certain number of disks from one peg to another.I write a recursive program for it.If you have known it ,you can skip the program. #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.