Home > Archive > C > December 2007 > main
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Does anyone know the file where the main function is defined?
thanks
| |
| Walter Roberson 2007-12-19, 6:58 pm |
| In article <f585bf14-e5d2-48ff-8235-63ce404d713f@r60g2000hsc.googlegroups.com>,
nick <cupofjava1961@aol.com> wrote:
>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.
| |
| Joachim Schmitz 2007-12-19, 6:58 pm |
| "nick" <cupofjava1961@aol.com> schrieb im Newsbeitrag
news:f585bf14-e5d2-48ff-8235-63ce404d713f@r60g2000hsc.googlegroups.com...
> Does anyone know the file where the main function is defined?
In the startup code of your implementation.
Bye, Jojo
| |
| Joachim Schmitz 2007-12-19, 6:58 pm |
| "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> schrieb im Newsbeitrag
news:fkbloe$gsl$1@online.de...
> "nick" <cupofjava1961@aol.com> schrieb im Newsbeitrag
> news:f585bf14-e5d2-48ff-8235-63ce404d713f@r60g2000hsc.googlegroups.com...
> In the startup code of your implementation.
nonsense, it's called from there, you have to define it yourself.
Bye, Jojo
| |
| santosh 2007-12-19, 6:58 pm |
| 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 **) { ... }
| |
| Richard Heathfield 2007-12-19, 6:58 pm |
| santosh said:
> nick wrote:
>
>
> 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
| |
| Chris Hills 2007-12-19, 6:58 pm |
| In article
<f585bf14-e5d2-48ff-8235-63ce404d713f@r60g2000hsc.googlegroups.com>,
nick <cupofjava1961@aol.com> writes
>Does anyone know the file where the main function is defined?
>
>thanks
In main.c
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
| |
| santosh 2007-12-19, 6:58 pm |
| Richard Heathfield wrote:
> santosh said:
>
>
> 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.
| |
| Richard Heathfield 2007-12-19, 6:58 pm |
| 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
| |
| Chris Hills 2007-12-19, 6:58 pm |
| In article <fkblsv$2ds$1@registered.motzarella.org>, santosh
<santosh.k83@gmail.com> writes
>nick wrote:
>
>
>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 /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
| |
|
| 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.
| |
| Shadowman 2007-12-19, 6:58 pm |
| Joachim Schmitz wrote:
> "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> schrieb im Newsbeitrag
> news:fkbloe$gsl$1@online.de...
> nonsense, it's called from there, you have to define it yourself.
Multiple personalities?
--
SM
rot13 for email
| |
| Richard Heathfield 2007-12-19, 6:58 pm |
| Chris Hills said:
> In article <fkblsv$2ds$1@registered.motzarella.org>, santosh
> <santosh.k83@gmail.com> writes
>
> 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
| |
| Joachim Schmitz 2007-12-19, 6:58 pm |
| "Shadowman" <funqbjzna615@pbzpnfg.arg> schrieb im Newsbeitrag
news:fkbof7$8v5$1@aioe.org...
> Joachim Schmitz wrote:
>
> Multiple personalities?
No, our fingers are just fast than our brains 8-)
Bye, Jojo
| |
| santosh 2007-12-19, 6:58 pm |
| 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.
| |
| santosh 2007-12-19, 6:58 pm |
| Chris Hills wrote:
> In article <fkblsv$2ds$1@registered.motzarella.org>, santosh
> <santosh.k83@gmail.com> writes
>
> 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.
| |
| Keith Thompson 2007-12-19, 6:58 pm |
| phao <ph.rpguo@gmail.com> writes:
> 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) kst-u@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"
| |
| Keith Thompson 2007-12-19, 6:58 pm |
| phao <ph.rpguo@gmail.com> writes:
> 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) <kst-u@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"
| |
|
| 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
| |
| Tor Rustad 2007-12-19, 6:58 pm |
| Chris Hills wrote:
> In article
> <f585bf14-e5d2-48ff-8235-63ce404d713f@r60g2000hsc.googlegroups.com>,
> nick <cupofjava1961@aol.com> writes
>
> In main.c
$ cat hello.c
#include <stdio.h>
int main(void) { printf("Not in main.c\n"); return 0; }
--
Tor <bwzcab@wvtqvm.vw | tr i-za-h a-z>
| |
| Tor Rustad 2007-12-19, 6:58 pm |
| Chris Hills wrote:
> In article <fkblsv$2ds$1@registered.motzarella.org>, santosh
> <santosh.k83@gmail.com> writes
>
> 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 <bwzcab@wvtqvm.vw | tr i-za-h a-z>
| |
|
| On Dec 19, 6:16 pm, Keith Thompson <ks...@mib.org> wrote:
> phao <ph.rp...@gmail.com> writes:
>
>
>
> 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.
>
>
> [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.
| |
| vippstar@gmail.com 2007-12-20, 9:58 pm |
| On Dec 19, 7:54 pm, santosh <santosh....@gmail.com> wrote:
> nick wrote:
>
>
> 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>
| |
| Keith Thompson 2007-12-20, 9:58 pm |
| vippstar@gmail.com writes:
> On Dec 19, 7:54 pm, santosh <santosh....@gmail.com> wrote:
[...]
>
> 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) <kst-u@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"
| |
| Malcolm McLean 2007-12-20, 9:58 pm |
| "pete" <pfiland@mindspring.com> wrote in message
> Chris Hills wrote:
>
>
> 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
| |
| Flash Gordon 2007-12-21, 3:58 am |
| In-Reply-To: <476B03AE.1A0E@mindspring.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <2lbs35xrfa.ln2@news.flash-gordon.me.uk>
X-Leafnode-NNTP-Posting-Host: 89.104.54.210
Lines: 32
NNTP-Posting-Host: 88.208.220.85
X-Trace: 1198227662 news.gradwell.net 513 spamtrap/88.208.220.85:35472
X-Complaints-To: news-abuse@gradwell.net
Bytes: 2299
Xref: number1.nntp.dca.giganews.com comp.lang.c:784115
pete wrote, On 21/12/07 00:07:
> Malcolm McLean wrote:
>
> 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
| |
| santosh 2007-12-21, 3:58 am |
| Flash Gordon wrote:
> pete wrote, On 21/12/07 00:07:
>
> 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>
| |
| Chris Hills 2007-12-21, 7:57 am |
| In article <fkfvmr$gp3$1@registered.motzarella.org>, santosh
<santosh.k83@gmail.com> writes
>Flash Gordon wrote:
>
>
>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 /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
| |
| Richard Heathfield 2007-12-21, 7:57 am |
| 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
| |
| Chris Hills 2007-12-21, 7:57 am |
| In article <5aWdnbpRj9BhCvbanZ2dnUVZ8uqdnZ2d@bt.com>, Richard Heathfield
<rjh@see.sig.invalid> writes
>Chris Hills said:
>
>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 /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
| |
| Richard Heathfield 2007-12-21, 7:57 am |
| Chris Hills said:
> In article <5aWdnbpRj9BhCvbanZ2dnUVZ8uqdnZ2d@bt.com>, Richard Heathfield
> <rjh@see.sig.invalid> writes
>
> 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
| |
|
| Richard Heathfield wrote:
>
> Chris Hills said:
>
> <snip>
>
>
> You appear to define "silly brigade"
> as "people who correct Chris Hills's mistakes".
>
>
> It isn't always appropriate even then,
> since freestanding implementations
> get to choose their own entry point function name and type.
>
> <snip>
>
>
> Not true, as has already been pointed out elsethread.
Chris Hills snipped this:
[color=darkred]
Perhaps "start_main", isn't sufficiently different from "main"?
--
pete
| |
|
| 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
| |
| Philip Potter 2007-12-21, 7:58 am |
| 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
| |
| Chris Hills 2007-12-21, 6:58 pm |
| In article <fkgfo8$pqa$2@aioe.org>, Philip Potter <pgp@doc.ic.ac.uk>
writes
>Chris Hills wrote:
>
>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 /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
| |
| santosh 2007-12-21, 6:58 pm |
| Chris Hills wrote:
> In article <fkgfo8$pqa$2@aioe.org>, Philip Potter <pgp@doc.ic.ac.uk>
> writes
>
> Precisely. Hence one of the problems
Not for anyone who knows the basics of C.
| |
| Flash Gordon 2007-12-21, 6:58 pm |
| Chris Hills wrote, On 21/12/07 10:19:
> In article <fkfvmr$gp3$1@registered.motzarella.org>, santosh
> <santosh.k83@gmail.com> writes
>
> 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
The TI C compiler for the TMS320C2x/C2xx/C5x series of DSPs does a call
to main. It even calls functions registered with atexit after main
returns or if exit or abort is called. After calling the registered
functions it enters an "infinite" loop.
> int main (void)
>
> would be appropriate.
TI only document:
main()
Yes, they rely on implicit int and don't specify (void) as the parameter
list. I don't think they have changed these areas of the manual since it
was originally written. On the bright side they do tell people to use
K&R2 "as a supplement to this manual" and at one point at least they
gave you a copy as part of the manual set. They also include a reference
to the original ANSI standard document as being useful.
> 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,
I agree it makes sense. However it is not universally documented as
being valid even for free-standing compilers that use main as the entry
point, let alone those that use something else.
> 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 (........
<snip>
> 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.
Agreed. This was the only point I was addressing.
> 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.
Real engineering and *not* standards pedantry says that not all C
implementations work as you claim. Had you said of "void main" that it
applied to "some", "many" or even "most" rather than making it
unqualified people would have been less likely to call you on it.
> However, unfortunately as so often on c.l.c the discussion has gone off
> on a tangent for the wrong reasons of pedantry.
My point in this post is based on my real engineering experience in a
real engineering company working on a number of real embedded systems
where the entry point was main but it was *not* "void main(...".
I don't know what market share Texas Instruments has currently, but from
the rate they were producing new processors when I was using them it
can't have been too small.
--
Flash Gordon
| |
| David Thompson 2007-12-30, 6:58 pm |
| On Thu, 20 Dec 2007 13:22:18 -0800, Keith Thompson <kst-u@mib.org>
wrote:
> vippstar@gmail.com writes:
>
> 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
|
|
|
|
|