473,763 Members | 7,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

elementary construction

Today is when I sing in the choir, and I was thinking about rehearsal
tonight when I realized that in order to be in the C choir, I had to buy K&R
to be reading the same "music."

I am familiar with http://www.eskimo.com/~scs/C-faq/top.html , but I found
no resolution to my first question, which crops up on page 6. I have always
called main with an integer that says how many pointers are being passed to
it. Is this just a matter of style?

Would int main(int a, int b, int c){ return (51);} be, while close to
trivial, ANSI compliant? MPJ
Nov 14 '05 #1
18 1391
Merrill & Michele <be********@com cast.net> scribbled the following:
Today is when I sing in the choir, and I was thinking about rehearsal
tonight when I realized that in order to be in the C choir, I had to buy K&R
to be reading the same "music." I am familiar with http://www.eskimo.com/~scs/C-faq/top.html , but I found
no resolution to my first question, which crops up on page 6. I have always
called main with an integer that says how many pointers are being passed to
it. Is this just a matter of style?
The first argument to main should be an integer saying the number of
arguments, the second should be a pointer to the arguments themselves.
It's not a matter of style, it's the standard requirement.
Would int main(int a, int b, int c){ return (51);} be, while close to
trivial, ANSI compliant? MPJ


No it would not.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogeneti c procreation in humans will result in the founding of a new
religion."
- John Nordberg
Nov 14 '05 #2
Merrill & Michele <be********@com cast.net> wrote:
I am familiar with http://www.eskimo.com/~scs/C-faq/top.html , but I found
no resolution to my first question, which crops up on page 6. I have always
called main with an integer that says how many pointers are being passed to
it. Is this just a matter of style? Would int main(int a, int b, int c){ return (51);} be, while close to
trivial, ANSI compliant? MPJ


No. The only versions of main() blessed by the standard are either
passing it nothing i.e.

int main( void )

or passing it an int and an array of char pointers

int main( int argc, char *argv[ ] )

which you also sometimes find written as

int main( int argc, char **argv )

with argv having argc+1 elements, argv[0] to argv[argc-1] pointing
to strings and argv[argc] being a null pointer. Of course, if you
want to confuse people reading your program you can give argc and
argv different names - for maximum effect exchange their names;-)

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #3
Merrill & Michele wrote:
Today is when I sing in the choir, and I was thinking about rehearsal
tonight when I realized that in order to be in the C choir, I had to buy K&R
to be reading the same "music."

I am familiar with http://www.eskimo.com/~scs/C-faq/top.html , but I found
no resolution to my first question, which crops up on page 6. I have always
called main with an integer that says how many pointers are being passed to
it. Is this just a matter of style?

Would int main(int a, int b, int c){ return (51);} be, while close to
trivial, ANSI compliant? MPJ


Not in a "hosted environment," which covers the vast
majority of general-purpose C implementations . Such an
implementation launches a program by taking care of some
necessary housekeeping (for example, initializing all
your `static' variables, setting up stdin/out/err, and
so forth) and then calling the main() function that you
supply. The implementation uses Implementation Magic(tm)
to accomplish all this, but isn't Magical enough to read
your mind about what sort of arguments your main() wants,
so it always provides an `int' and a `char**'. If your
main() expects something else, unpredictable confusion
will arise.

Actually, there is one further bit of Magic: You can
write your main() to expect no arguments at all, and the
implementation is required to call it anyhow. Thus, there
are two valid "signatures " for main():

int main(int, char**);
int main(void);

(There are, of course, other ways to express these two
possibilities.)

Now, a particular C implementation may also support
other main() signatures in addition to the two required
by the language -- a common extension is

int main(int, char**, char**);

where the third (non-standard) argument points to an
array of "environmen t variables." The Standard does not
forbid such alternate forms for main(), but also does not
require them. You can use other forms if your platform
supports them, but all bets are off when you move your
code to a different platform.

All this pertains to "hosted environments." The C
Standard also considers "free-standing environments," the
sort of C implementation that might operate your microwave
oven or your talking toilet. (I'm not kidding; use Google.)
These environments make their own provisions for invoking
and terminating programs, and main() may have a completely
different form -- it may not even have any special meaning
at all. Indeed, there may be no such concept as "program
start" or "program finish;" the program may simply run as
long as the electricity keeps flowing.

Finally, a word about all that Implementation Magic(tm).
I've said it "calls main()," but in fact the actual means by
which main() begins to execute need not be a bona-fide C
language function call. The implementation must make it
appear "as if" main() has been called from a higher-order
function, but the means by which this happens could be
mysterious in the extreme. You really needn't worry about
this because once your main() receives control it seems to
have been called in ordinary fashion; I'm only mentioning
this to keep my fellow pedants off my case.

To return to your music analogy, when you're "hosted"
by a choir with an organ and/or piano and/or orchestra,
tuning to A = 440Hz is all but mandatory; you use the
standard forms for main(). Some groups with an interest in
early music may deliberately use older tunings like A=435Hz;
some platforms support alternate main() forms. And when
you're singing in the shower, "Nessun dorma" sounds a lot
better if you slide that A down to 370Hz or so; there are
no standards for main() in a free-standing shower stall.

--
Er*********@sun .com

Nov 14 '05 #4
And what characters are legal in the main call? I know I can use argc and
banana. What about % or a number? Common sense says that you don't try to
confuse somebody with a main call, but I'm wondering about ANSI compliance
or feasibility. MPJ
Nov 14 '05 #5
In article <pq************ ********@comcas t.com>,
Merrill & Michele <be********@com cast.net> wrote:
And what characters are legal in the main call?
Anything that's legal (that is, well-formed and not reserved) as an
identifier for any other function argument.
I know I can use argc and
banana. What about %
Nope, neither in main's arguments nor in any other variable name.
Only if you want the integer modulus operation, a printf format modifier,
or the digraphs for '{', '}', or '#'.
or a number?
Not a decimal representation of a number on its own, but something like
'fortytwo' or 'not_42' is OK.
Common sense says that you don't try to
confuse somebody with a main call, but I'm wondering about ANSI compliance
or feasibility. MPJ


No different from any other function interface: The number and type of
arguments are defined, but you can call them anything you like, within
the restrictions on which identifiers are legal.
dave

--
Dave Vandervies dj******@csclub .uwaterloo.ca
Basically, there is no control structure you can imagine that
can't be implemented using call/cc. Even very silly ones.
--Bear in comp.lang.schem e
Nov 14 '05 #6
> No different from any other function interface: The number and type of
arguments are defined, but you can call them anything you like, within
the restrictions on which identifiers are legal.


I am going to beat this horse until I think it's dead. The following
compiles for me. Is it ANSI compliant?

#include <stdio.h>

int main(int argc, char* [])
{

return 0;
}

So am I to think of the main call as being like any other C function call?
I've always thought of it differently. MPJ

Nov 14 '05 #7
On Wed, 22 Sep 2004 21:15:13 -0500, "Merrill & Michele"
<be********@com cast.net> wrote in comp.lang.c:
No different from any other function interface: The number and type of
arguments are defined, but you can call them anything you like, within
the restrictions on which identifiers are legal.
I am going to beat this horse until I think it's dead. The following
compiles for me. Is it ANSI compliant?

#include <stdio.h>

int main(int argc, char* [])


This is an error requiring a diagnostic. In a function definition all
arguments must have names. If is only in a function prototype that
the names may be omitted.
{

return 0;
}

So am I to think of the main call as being like any other C function call?
I've always thought of it differently. MPJ


In C, main() is _almost_ like any other function. Prior to C99 it had
only one difference, in that it could be called either with no
arguments (int main(void)) or two arguments (int main(int argc, char
**argv).

C99, the 1999 major update to the C standard, added one other special
property to main, that is if main() is properly defined with a return
type of int and one of the two standard sets of arguments, the effect
of hitting the closing brace without executing a return statement is
the same as executing "return 0;".

This applies _only_ to the initial call to main() at program start up,
and is not guaranteed to work equivalently if main() is called
recursively from within a program.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #8

In article <41************ **@sun.com>, Eric Sosman <Er*********@su n.com> writes:

All this pertains to "hosted environments." The C
Standard also considers "free-standing environments," the
sort of C implementation that might operate your microwave
oven or your talking toilet.


Don't forget the popular freestanding implementation for Microsoft
Windows programs called "GUI mode". I'm willing to be that there are
quite a few C programmers who've had to develop for that freestanding
environment at one time or another. I have (and the memory is seared
into my brain).

There the program's initial function is called "WinMain", and it has
parameters that are quite different from main's.

--
Michael Wojcik mi************@ microfocus.com

The lark is exclusively a Soviet bird. The lark does not like the
other countries, and lets its harmonious song be heard only over the
fields made fertile by the collective labor of the citizens of the
happy land of the Soviets. -- D. Bleiman
Nov 14 '05 #9
In <L5************ ********@comcas t.com> "Merrill & Michele" <be********@com cast.net> writes:
No different from any other function interface: The number and type of
arguments are defined, but you can call them anything you like, within
the restrictions on which identifiers are legal.
I am going to beat this horse until I think it's dead. The following
compiles for me. Is it ANSI compliant?


Only if you use a broken compiler.
#include <stdio.h>

int main(int argc, char* [])
{

return 0;
}
fangorn:~/tmp 218> gcc test.c
test.c: In function `main':
test.c:3: error: parameter name omitted
So am I to think of the main call as being like any other C function call?


The *initial* call of main(), that comes from outside your C code is
special. It must work no matter which of the two supported definitions
of main is used and, if main() returns, the program termination sequence
must be initiated. If the program calls main() itself, these calls are
perfectly ordinary: they must match the actual definition of main() and
returning from main() has no special semantics.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #10

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

Similar topics

1
1560
by: Anthony | last post by:
Hi, Can anyone help me out here, I'm looking for a design (pattern?) for a-synchronic construction of a class. I need this design in a framework which will run in a multithreaded system. I want a class (client) in threadA to a-synchronously construct a class (server) in threadB. Both threads will probably need a kind of construction manager object. For passing the request I will probably need to use a parameterised class.
2
1696
by: Steve | last post by:
Hi Folks, Sorry for this stupid question, but how do you handle errors during class construction. In other words, if I have a class that loads a file, and during loading, an error occurs, how do you deal with this in respect of releasing the resources that would have been allocated if the load was successful? What I am trying to achieve is, if I call my class with new, how do I return NULL if the construction fails (so I can check for...
14
1991
by: trying_to_learn | last post by:
i am on the chapter on copy construction in C++ in the code (see below), the author says if u pass the object by value as in HowMany h2 = f(h); ....then a bitwise object is created w/o calling the constructor of the class. However he says when we leave scope of function HowMany f(HowMany x) then the destructor is called. why this inconsistency?. Accdng to me even the destructor should *not* be called. i can understand that bit wise copy...
5
2847
by: Lionel B | last post by:
Greetings, I am trying to implement "element-wise" arithmetic operators for a class along the following lines (this is a simplified example): // ----- BEGIN CODE ----- struct X { int a,b;
29
1880
by: Merrill & Michele | last post by:
I'm now looking at page 115 K&R. After having discussed counterexamples, I shall herewith and henceforth make all my c programs look like int main(int orange, char* apple) {return(0);} Q1) How large is that int and that char*? (My instinct would be to look at limits.h, but with the main call, I can't figure out to what extent I'm %inside% C.)
0
2891
by: Geoffrey L. Collier | last post by:
I wrote a bunch of code to do elementary statistics in VB, and would prefer to find code in C# to recoding all of the VB code. A search of the web found very little. Does anyone know of a good set of classes to do these things, free, or for fee? Thanks, Geoff Collier
8
1510
by: pauldepstein | last post by:
I am writing a program which looks at nodes which have coordinates which are time-dependent. So I have a class called node which contains the private member declarations int date; int month; (I want to consider the month as part of the information contained in the node, as well as the date.) The node class also contains public member function void set_month(int) which sets the month according to the date given.
5
2535
by: bromio | last post by:
can someone help me to make code for digital clock using AT89S52. The specs of clock are 12 hour clock,am-pm display,use timer interrupts to have delay.two external inputs to adjust hours and minutes,use 4 digit hex display multiplexing.
7
3412
by: BeautifulMind | last post by:
In case of inheritence the order of execution of constructors is in the order of derivation and order of destructor execution is in reverse order of derivation. Is this case also true in case class is derived as virtual? How does the order of construction/destruction is impacted if the base class is derived as virtual or non virtual? just see the example below.
15
2408
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.