473,406 Members | 2,273 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,406 software developers and data experts.

main

Does anyone know the file where the main function is defined?

thanks
Dec 19 '07 #1
37 1894
In article <f5**********************************@r60g2000hsc. googlegroups.com>,
nick <cu***********@aol.comwrote:
>Does anyone know the file where the main function is defined?
main() can be defined in any (one) file that your compiler will
accept as being C source code. It would be perfectly acceptable
for example to define main() in e5d248f.c or some other
arbitrary filename.

It is -common- for programmers to define main() in a source
file whose base name (without the suffix) is the same as the
eventual executable name (without its suffix), but that is by no
means a requirement and is not even common enough to be considered
"semi-standard".
--
We regret to announce that sub-millibarn resolution bio-hyperdimensional
plasmatic space polyimaging has been delayed until the release
of Windows Vista SP2.
Dec 19 '07 #2
"nick" <cu***********@aol.comschrieb im Newsbeitrag
news:f5**********************************@r60g2000 hsc.googlegroups.com...
Does anyone know the file where the main function is defined?
In the startup code of your implementation.

Bye, Jojo
Dec 19 '07 #3
"Joachim Schmitz" <no*********@schmitz-digital.deschrieb im Newsbeitrag
news:fk**********@online.de...
"nick" <cu***********@aol.comschrieb im Newsbeitrag
news:f5**********************************@r60g2000 hsc.googlegroups.com...
>Does anyone know the file where the main function is defined?
In the startup code of your implementation.
nonsense, it's called from there, you have to define it yourself.

Bye, Jojo
Dec 19 '07 #4
nick wrote:
Does anyone know the file where the main function is defined?

thanks
For each program, the programmer must define the main function. Only the
portable forms of main's header are defined by the Standard. They are:

int main(void) { ... }

and

int main(int, char **) { ... }

Dec 19 '07 #5
santosh said:
nick wrote:
>Does anyone know the file where the main function is defined?

thanks

For each program, the programmer must define the main function. Only the
portable forms of main's header are defined by the Standard. They are:

int main(void) { ... }

and

int main(int, char **) { ... }
The second form is illegal. Either you meant ; rather than { or you meant
to say:

int main(int argc, char **argv)

or some exact equivalent.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 19 '07 #6
In article
<f5**********************************@r60g2000hsc. googlegroups.com>,
nick <cu***********@aol.comwrites
>Does anyone know the file where the main function is defined?

thanks
In main.c

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Dec 19 '07 #7
Richard Heathfield wrote:
santosh said:
>nick wrote:
>>Does anyone know the file where the main function is defined?

thanks

For each program, the programmer must define the main function. Only
the portable forms of main's header are defined by the Standard. They
are:

int main(void) { ... }

and

int main(int, char **) { ... }

The second form is illegal. Either you meant ; rather than { or you
meant to say:

int main(int argc, char **argv)

or some exact equivalent.
Yes. You are correct thanks. I should have written them as declarations.

Dec 19 '07 #8
santosh said:

<snip>
I should have written them as declarations.
You did. :-) That wasn't your mistake. Your mistake was in using the form
that can only be a declaration and is never a definition, in a context
where a definition was required. The two solutions that spring to mind
are: (a) fix the declaration so that it's in suitable form for a
definition too, or (b) change the context from {} to ;.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 19 '07 #9
In article <fk**********@registered.motzarella.org>, santosh
<sa*********@gmail.comwrites
>nick wrote:
>Does anyone know the file where the main function is defined?

thanks

For each program, the programmer must define the main function. Only the
portable forms of main's header are defined by the Standard. They are:

int main(void) { ... }

and

int main(int, char **) { ... }
There is

void main(void)

but this is ONLY for self hosted systems (ie no OS) as there is nothing
to return to. The start up assembler jumps to main with an explicit jump
and no return address.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Dec 19 '07 #10
if your problem is having a lot of sources and want to know where
main() is, you can use shellscript plus regular expressions to solve
this problem

grep -nE '^main\(.*\)' file list here

i think it'll work, but you need the 'main' word as first word of the
line, most code you'll find out there you have this format of main
implementation.

int
main(int argc, char **argv)
{
....
}

so, if you have the 'int' lines before the 'main(...)' it'll work, you
can do a 'better work' upon this grep command to get a better job, and
match more than this situation.

it'll tell to you the file name (if you specify more than one) and the
line number in which main is.

i've done this using grep from GNU.
Dec 19 '07 #11
Joachim Schmitz wrote:
"Joachim Schmitz" <no*********@schmitz-digital.deschrieb im Newsbeitrag
news:fk**********@online.de...
>"nick" <cu***********@aol.comschrieb im Newsbeitrag
news:f5**********************************@r60g200 0hsc.googlegroups.com...
>>Does anyone know the file where the main function is defined?
In the startup code of your implementation.
nonsense, it's called from there, you have to define it yourself.
Multiple personalities?

--
SM
rot13 for email
Dec 19 '07 #12
Chris Hills said:
In article <fk**********@registered.motzarella.org>, santosh
<sa*********@gmail.comwrites
>>nick wrote:
>>Does anyone know the file where the main function is defined?

thanks

For each program, the programmer must define the main function. Only the
portable forms of main's header are defined by the Standard. They are:

int main(void) { ... }

and

int main(int, char **) { ... }

There is

void main(void)
Chapter and verse, please. Or are you merely referring to the same part of
the Standard that sanctions struct tm *main(double ***, struct ldiv_t) ?
but this is ONLY for self hosted systems (ie no OS) as there is nothing
to return to.
No, *any* freestanding implementation is free to define its own entry point
function name and type. On one Windows-based implementation I used to use,
for example, the entry point is defined as

int WINAPI WinMain(HINSTANCE Instance,
HINSTANCE PrevInstance,
PSTR CommandLine,
int WindowShow)

(This is sufficient to demonstrate that the implementation is either
freestanding or non-conforming.)

Of course, you could argue that Windows is not an OS, and that it's
"nothing to return to". :-)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 19 '07 #13
"Shadowman" <fu**********@pbzpnfg.argschrieb im Newsbeitrag
news:fk**********@aioe.org...
Joachim Schmitz wrote:
>"Joachim Schmitz" <no*********@schmitz-digital.deschrieb im Newsbeitrag
news:fk**********@online.de...
>>"nick" <cu***********@aol.comschrieb im Newsbeitrag
news:f5**********************************@r60g20 00hsc.googlegroups.com...
Does anyone know the file where the main function is defined?
In the startup code of your implementation.
nonsense, it's called from there, you have to define it yourself.

Multiple personalities?
No, our fingers are just fast than our brains 8-)

Bye, Jojo
Dec 19 '07 #14
phao wrote:
if your problem is having a lot of sources and want to know where
main() is, you can use shellscript plus regular expressions to solve
this problem

grep -nE '^main\(.*\)' file list here
<snip>

Frankly, I prefer to put the main definition in a file whose basename is
the name the program executable (or main driver) will take, or in a
file called 'main.c'.

I think the latter convention is the better one.

Dec 19 '07 #15
Chris Hills wrote:
In article <fk**********@registered.motzarella.org>, santosh
<sa*********@gmail.comwrites
>>nick wrote:
>>Does anyone know the file where the main function is defined?

thanks

For each program, the programmer must define the main function. Only
the portable forms of main's header are defined by the Standard. They
are:

int main(void) { ... }

and

int main(int, char **) { ... }

There is

void main(void)

but this is ONLY for self hosted systems (ie no OS) as there is
nothing to return to. The start up assembler jumps to main with an
explicit jump and no return address.
Yes, but even here it really depends on the particular project in
question. In any case the canonical form will do no harm, since main
isn't ever going to return anyway. A return value makes sense only when
the function actually returns.

Dec 19 '07 #16
phao <ph******@gmail.comwrites:
if your problem is having a lot of sources and want to know where
main() is, you can use shellscript plus regular expressions to solve
this problem

grep -nE '^main\(.*\)' file list here

i think it'll work, but you need the 'main' word as first word of the
line, most code you'll find out there you have this format of main
implementation.
You're assuming that the "grep" command is available and does what you
expect it to do. There are C implementations on plenty of
non-Unix-like systems. Knowing how to use text processing tools (like
grep) on C source files is a valuable skill, but the details are going
to vary from one system to another.
int
main(int argc, char **argv)
{
...
}
[snip]

Some coding styles require the function name to occur at the beginning
of the line, but not all do. Personally, I prefer to put the function
declaration on a single line:

int main(int argc, char **argv)
{
....
}

Admittedly this can be less convenient for some purposes.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 19 '07 #17
phao <ph******@gmail.comwrites:
if your problem is having a lot of sources and want to know where
main() is, you can use shellscript plus regular expressions to solve
this problem

grep -nE '^main\(.*\)' file list here

i think it'll work, but you need the 'main' word as first word of the
line, most code you'll find out there you have this format of main
implementation.
You're assuming that the "grep" command is available and does what you
expect it to do. There are C implementations on plenty of
non-Unix-like systems. Knowing how to use text processing tools (like
grep) on C source files is a valuable skill, but the details are going
to vary from one system to another.
int
main(int argc, char **argv)
{
...
}
[snip]

Some coding styles require the function name to occur at the beginning
of the line, but not all do. Personally, I prefer to put the function
declaration on a single line:

int main(int argc, char **argv)
{
....
}

Admittedly this can be less convenient for some purposes.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 19 '07 #18
Chris Hills wrote:
There is

void main(void)

but this is ONLY for self hosted systems
(ie no OS) as there is nothing to return to.
It is for freestanding implementations if and only if,
the particular freestanding implementations in question,
choose that particular way,
to define the function which is called at start up.

--
pete
Dec 19 '07 #19
Chris Hills wrote:
In article
<f5**********************************@r60g2000hsc. googlegroups.com>,
nick <cu***********@aol.comwrites
>Does anyone know the file where the main function is defined?

thanks

In main.c
$ cat hello.c
#include <stdio.h>

int main(void) { printf("Not in main.c\n"); return 0; }

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Dec 19 '07 #20
Chris Hills wrote:
In article <fk**********@registered.motzarella.org>, santosh
<sa*********@gmail.comwrites
>nick wrote:
>>Does anyone know the file where the main function is defined?

thanks

For each program, the programmer must define the main function. Only the
portable forms of main's header are defined by the Standard. They are:

int main(void) { ... }

and

int main(int, char **) { ... }

There is

void main(void)

but this is ONLY for self hosted systems (ie no OS) as there is nothing
to return to. The start up assembler jumps to main with an explicit jump
and no return address.
Nope, the name and type of function called at startup in a free-standing
environment, is implementation-defined.

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Dec 19 '07 #21
On Dec 19, 6:16 pm, Keith Thompson <ks...@mib.orgwrote:
phao <ph.rp...@gmail.comwrites:
if your problem is having a lot of sources and want to know where
main() is, you can use shellscript plus regular expressions to solve
this problem
grep -nE '^main\(.*\)' file list here
i think it'll work, but you need the 'main' word as first word of the
line, most code you'll find out there you have this format of main
implementation.

You're assuming that the "grep" command is available and does what you
expect it to do. There are C implementations on plenty of
non-Unix-like systems. Knowing how to use text processing tools (like
grep) on C source files is a valuable skill, but the details are going
to vary from one system to another.
int
main(int argc, char **argv)
{
...
}

[snip]

Some coding styles require the function name to occur at the beginning
of the line, but not all do. Personally, I prefer to put the function
declaration on a single line:

int main(int argc, char **argv)
{
...

}

Admittedly this can be less convenient for some purposes.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
i agree with you.

but i've specified that the command i've used to find the 'main' was
done in a grep program from GNU (so using program = 'grep' and O.S. =
'gnu').

i've specified, also, that the command ONLY works for specifications
of 'main' using that format or something similar, and to make
something to mach other specification format of 'main' like yours,
you'd have to do a better command.

so it is indeed restrict to that situation.

but it was just 'another' option, not the ONLY option.

and my post was, also, to give another idea about solving the problem,
it's not to be the perfect solution.

so, you're right.
Dec 20 '07 #22
On Dec 19, 7:54 pm, santosh <santosh....@gmail.comwrote:
nick wrote:
Does anyone know the file where the main function is defined?
thanks

For each program, the programmer must define the main function. Only the
portable forms of main's header are defined by the Standard. They are:

int main(void) { ... }

and

int main(int, char **) { ... }
so this is not valid?

typedef char ** foo;
int main(int argc, foo argv) { ... }

Or
int main(int argc, char *argv[]) { ... }

?
what about argv[][]

These are valid as well

refer to <http://clc-wiki.net/wiki/Main>
Dec 20 '07 #23
vi******@gmail.com writes:
On Dec 19, 7:54 pm, santosh <santosh....@gmail.comwrote:
[...]
>For each program, the programmer must define the main function. Only the
portable forms of main's header are defined by the Standard. They are:

int main(void) { ... }

and

int main(int, char **) { ... }

so this is not valid?

typedef char ** foo;
int main(int argc, foo argv) { ... }
Yes, that's valid.
Or
int main(int argc, char *argv[]) { ... }

?
That's valid too.
what about argv[][]
No, that's not valid. "char *argv[]" as a parameter declaration is
equivalent to "char **argv", but the rule can only be applied once.
"char argv[][]" as a parameter declaration declares argv as pointer to
an incomplete array of char, which is illegal.
These are valid as well

refer to <http://clc-wiki.net/wiki/Main>
Right. santosh's point was that in a *definition* of main, you have
to provide names for the parameters, not just types. In a declaration
that's not a definition, you're free to omit the names.

In short, the portable forms for main are:
int main(void)
and
int main(int argc, char *argv[])
*and equivalent forms*. Equivalence covers using "char **argv" rather
than "char *argv[]", using different names for the parameters (but not
for the function!), and using typedefs.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 20 '07 #24
"pete" <pf*****@mindspring.comwrote in message
Chris Hills wrote:
>There is

void main(void)

but this is ONLY for self hosted systems
(ie no OS) as there is nothing to return to.

It is for freestanding implementations if and only if,
the particular freestanding implementations in question,
choose that particular way,
to define the function which is called at start up.
Often it is called something like "boot" and you have to tell it to load the
rest of the program, configure stacks and data pages and the like, before
doing any useful processing.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Dec 20 '07 #25
Malcolm McLean wrote:
>
"pete" <pf*****@mindspring.comwrote in message
Chris Hills wrote:
There is

void main(void)

but this is ONLY for self hosted systems
(ie no OS) as there is nothing to return to.
It is for freestanding implementations if and only if,
the particular freestanding implementations in question,
choose that particular way,
to define the function which is called at start up.
Often it is called something like "boot"
and you have to tell it to load the rest of the program,
configure stacks and data pages and the like, before
doing any useful processing.
The only time that I used a C cross compiler,
the name of the program startup function was start_main
and I don't remember the type of the function.

--
pete
Dec 21 '07 #26
pete wrote, On 21/12/07 00:07:
Malcolm McLean wrote:
>"pete" <pf*****@mindspring.comwrote in message
>>Chris Hills wrote:

There is

void main(void)

but this is ONLY for self hosted systems
(ie no OS) as there is nothing to return to.
It is for freestanding implementations if and only if,
the particular freestanding implementations in question,
choose that particular way,
to define the function which is called at start up.
Often it is called something like "boot"
and you have to tell it to load the rest of the program,
configure stacks and data pages and the like, before
doing any useful processing.

The only time that I used a C cross compiler,
the name of the program startup function was start_main
and I don't remember the type of the function.
The ones I used there was a startup "function" which was not written in
C (and so was not the entry as far as C was concerned) that did all the
stuff that Malcolm referred to and which you could modify and this
function then called main. I can't remember the signature it used for
main though.
--
Flash Gordon
Dec 21 '07 #27
Flash Gordon wrote:
pete wrote, On 21/12/07 00:07:
>Malcolm McLean wrote:
>>"pete" <pf*****@mindspring.comwrote in message
Chris Hills wrote:

There is
>
void main(void)
>
but this is ONLY for self hosted systems
(ie no OS) as there is nothing to return to.
It is for freestanding implementations if and only if,
the particular freestanding implementations in question,
choose that particular way,
to define the function which is called at start up.

Often it is called something like "boot"
and you have to tell it to load the rest of the program,
configure stacks and data pages and the like, before
doing any useful processing.

The only time that I used a C cross compiler,
the name of the program startup function was start_main
and I don't remember the type of the function.

The ones I used there was a startup "function" which was not written
in C (and so was not the entry as far as C was concerned) that did all
the stuff that Malcolm referred to and which you could modify and this
function then called main. I can't remember the signature it used for
main though.
Usually the startup code is in assembler and it invokes 'main' with
whatever is that assembler's instruction for invoking a subroutine.

<OT>
A sequence for x86 might be similar to this:

_start:
; initialisation
push envp
push argv
push argc
call main
; cleanup and return to host
</OT>

Dec 21 '07 #28
In article <fk**********@registered.motzarella.org>, santosh
<sa*********@gmail.comwrites
>Flash Gordon wrote:
>pete wrote, On 21/12/07 00:07:
>>Malcolm McLean wrote:
"pete" <pf*****@mindspring.comwrote in message
Chris Hills wrote:
>
>There is
>>
>void main(void)
>>
>but this is ONLY for self hosted systems
>(ie no OS) as there is nothing to return to.
It is for freestanding implementations if and only if,
the particular freestanding implementations in question,
choose that particular way,
to define the function which is called at start up.
>
Often it is called something like "boot"
and you have to tell it to load the rest of the program,
configure stacks and data pages and the like, before
doing any useful processing.

The only time that I used a C cross compiler,
the name of the program startup function was start_main
and I don't remember the type of the function.

The ones I used there was a startup "function" which was not written
in C (and so was not the entry as far as C was concerned) that did all
the stuff that Malcolm referred to and which you could modify and this
function then called main. I can't remember the signature it used for
main though.

Usually the startup code is in assembler and it invokes 'main' with
whatever is that assembler's instruction for invoking a subroutine.

<OT>
A sequence for x86 might be similar to this:

_start:
; initialisation
push envp
push argv
push argc
call main
; cleanup and return to host
</OT>
Normally, and this is the important point, it is NOT a "call" but a
jump. If it were a call you could expect it to return and therefore

int main (void)

would be appropriate.

However my original point before the silly brigade took over was that

void main (void)

is ONLY appropriate in self hosted or free-standing systems ie no
RTOS, sorry OS, and therefore at ALL OTHER TIMES main should have a
suitable return type and more importantly actually use the return type
properly. So it should be

int main (........

At one time in the Mysts of Tyme ie more than 9 terms ago (3 years) and
before the Linux beast roamed the land people did program on systems
with an OS and use

main()
{
...........

Which later became

void main (....

A bad habit.

As pointed out here the code before main (or the entry point to the C)
in a self hosted system is assembler which sets up the memory spaces,
bus endian, interrupts et al. depending on the system.

As pointed out in a self hosted system "main" or the entry point to C
does not technically have to be called "main" but invariably is. At one
time many debug tools for embedded systems required the entry point to
the C to be called "main". However this is real engineering not
language standards pedantry.

However, unfortunately as so often on c.l.c the discussion has gone off
on a tangent for the wrong reasons of pedantry.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Dec 21 '07 #29
Chris Hills said:

<snip>
However my original point before the silly brigade took over
You appear to define "silly brigade" as "people who correct Chris Hills's
mistakes".
was that

void main (void)

is ONLY appropriate in self hosted or free-standing systems ie no
RTOS, sorry OS,
It isn't always appropriate even then, since freestanding implementations
get to choose their own entry point function name and type.

<snip>
As pointed out in a self hosted system "main" or the entry point to C
does not technically have to be called "main" but invariably is.
Not true, as has already been pointed out elsethread.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 21 '07 #30
In article <5a******************************@bt.com>, Richard Heathfield
<rj*@see.sig.invalidwrites
>Chris Hills said:
>was that

void main (void)

is ONLY appropriate in self hosted or free-standing systems ie no
RTOS, sorry OS,

It isn't always appropriate even then, since freestanding implementations
get to choose their own entry point function name and type.

<snip>
As I said before you snipped it

"As pointed out in a self hosted system "main" or the entry point to C
does not technically have to be called "main" but invariably is. At one
time many debug tools for embedded systems required the entry point to
the C to be called "main". However this is real engineering not
language standards pedantry."
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Dec 21 '07 #31
Chris Hills said:
In article <5a******************************@bt.com>, Richard Heathfield
<rj*@see.sig.invalidwrites
>>Chris Hills said:
>>was that

void main (void)

is ONLY appropriate in self hosted or free-standing systems ie no
RTOS, sorry OS,

It isn't always appropriate even then, since freestanding implementations
get to choose their own entry point function name and type.

<snip>

As I said before you snipped it

"As pointed out in a self hosted system "main" or the entry point to C
does not technically have to be called "main" but invariably is.
Wrong. (a) I did not snip this sentence. Rather, I commented on it. (b) My
comment pointed out why the sentence is incorrect.
At one
time many debug tools for embedded systems required the entry point to
the C to be called "main". However this is real engineering not
language standards pedantry."
I snipped this, however, because I had no comment to make on it. But now
that I have another opportunity so to do, I will take that opportunity to
point out that it's one thing to say "many [systems] required", and quite
another to say "invariably". I have no problem with your claim that many
embedded system debug tools require an entry point of "main". My objection
is to your claim that the entry point to C is *invariably* called main.

What you call "pedantry", I call "correctness". If you don't wish people to
post corrections to your statements, don't make incorrect statements.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 21 '07 #32
Richard Heathfield wrote:
>
Chris Hills said:

<snip>
However my original point before the silly brigade took over

You appear to define "silly brigade"
as "people who correct Chris Hills's mistakes".
was that

void main (void)

is ONLY appropriate in self hosted or free-standing systems ie no
RTOS, sorry OS,

It isn't always appropriate even then,
since freestanding implementations
get to choose their own entry point function name and type.

<snip>
As pointed out in a self hosted system
"main" or the entry point to C
does not technically have to be called "main" but invariably is.

Not true, as has already been pointed out elsethread.
Chris Hills snipped this:
The only time that I used a C cross compiler,
the name of the program startup function was start_main
Perhaps "start_main", isn't sufficiently different from "main"?

--
pete
Dec 21 '07 #33
Chris Hills wrote:
However my original point before the silly brigade took over was that

void main (void)

is ONLY appropriate in self hosted or free-standing systems ie no
RTOS, sorry OS, and therefore at ALL OTHER TIMES main should have a
suitable return type and more importantly actually use the return type
properly. So it should be

int main (........
According to ISO/IEC 9899:1999 (E),
your point is pointless because implementation defined forms of main
exist both in freestanding implementations of C and also in
hosted implementations of C.

"void main (void)" is no more likely to be an implementation
defined startup function name on a freestanding implementation
than it is likely to be on a hosted implementation.

--
pete
Dec 21 '07 #34
Chris Hills wrote:
At one time in the Mysts of Tyme ie more than 9 terms ago (3 years) and
before the Linux beast roamed the land people did program on systems
with an OS and use

main()
{
..........

Which later became

void main (....

A bad habit.
Did one become the other? They don't mean the same thing. C89 implicit
int meant that

f() {
/*...*/
}

was the same as

int f() {
/*...*/
}

so therefore main() is the same as int main(), not void main().

Philip
Dec 21 '07 #35
In article <fk**********@aioe.org>, Philip Potter <pg*@doc.ic.ac.uk>
writes
>Chris Hills wrote:
>At one time in the Mysts of Tyme ie more than 9 terms ago (3 years)
and before the Linux beast roamed the land people did program on
systems with an OS and use
main()
{
..........
Which later became
void main (....
A bad habit.

Did one become the other? They don't mean the same thing. C89 implicit
int meant that

f() {
/*...*/
}

was the same as

int f() {
/*...*/
}

so therefore main() is the same as int main(), not void main().

Philip
Precisely. Hence one of the problems
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Dec 21 '07 #36
Chris Hills wrote:
In article <fk**********@aioe.org>, Philip Potter <pg*@doc.ic.ac.uk>
writes
>>Chris Hills wrote:
>>At one time in the Mysts of Tyme ie more than 9 terms ago (3 years)
and before the Linux beast roamed the land people did program on
systems with an OS and use
main()
{
..........
Which later became
void main (....
A bad habit.

Did one become the other? They don't mean the same thing. C89 implicit
int meant that

f() {
/*...*/
}

was the same as

int f() {
/*...*/
}

so therefore main() is the same as int main(), not void main().

Philip

Precisely. Hence one of the problems
Not for anyone who knows the basics of C.

Dec 21 '07 #37
On Thu, 20 Dec 2007 13:22:18 -0800, Keith Thompson <ks***@mib.org>
wrote:
vi******@gmail.com writes:
what about argv[][]

No, that's not valid. "char *argv[]" as a parameter declaration is
equivalent to "char **argv", but the rule can only be applied once.
That's true.
"char argv[][]" as a parameter declaration declares argv as pointer to
an incomplete array of char, which is illegal.
Pointer to unspecified-bound array is largely useless, and certainly
wrong for the second parameter of main(), but not illegal in itself.

In C89 _if_ the rewrite is done first -- as seems reasonable, but is
nowhere that I have found strictly required -- this can be accepted.
In C99 it is a constraint on the declarator that the element type not
be incomplete, and thus presumably applies even in the rewrite case.
In C89 it was only a non-constraint 'shall' on an/the actual type.

<snip rest>
- formerly david.thompson1 || achar(64) || worldnet.att.net
Dec 30 '07 #38

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

Similar topics

192
by: Kwan Ting | last post by:
The_Sage, I see you've gotten yourself a twin asking for program in comp.lang.c++ . http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1 If you the oh so mighty...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
15
by: Fred Zwarts | last post by:
In C++ execution of a program starts already before execution of main(). The initialization of static variables defined outside the scope of main is performed first. I could imagine a program where...
75
by: Beni | last post by:
I have been programming in C for about a year now. It sounds silly, but I never took the time to question why a C(or C++ or Java) program execution begins only at the main(). Is it a convention or...
5
by: Seong-Kook Shin | last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version, and have two question regarding to Q11.16 ... Also, a `return' from `main' cannot be expected to work if data local to main might be...
13
by: Sokar | last post by:
I have my main function set up as int main(int argv, char *argv) so taht i can read in a variable which is passed to the program on the command line. The problem is that main calls other...
16
by: Geoff Jones | last post by:
Hi What is the closest equivalent to Main in a VB.Net form? Geoff
2
by: psuaudi | last post by:
I have a main query that I would like to call two different subqueries. In MS Access, I usually just save the two subqueries as separate queries which are then called by a third separate and main...
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
11
by: aarklon | last post by:
Hi all, I have heard many discussions among my colleagues that main is a user defined function or not. arguments in favour:- 1) if it is built in function it must be defined in some header...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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
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...

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.