I am learning C: a little problem with a simple source code

K

Kaz Kylheku

The main argument (no pun intended) is that the programming usage
follows from mathematics: f(x) and so on. Even having seen the inserted
space for some time (I thinks it's relatively new) I still can't shake
off the sense it gives of a parenthetical remark:

f(x) + y // f applied to x plus y
f (x) + y // f plus y (and by the way, x)

Silly, I know, but it's only fair that there be a comment from someone
who hates this style!

F (X) is only appropriate when F is a macro or operator, and (X) is not
evaluated as a normal function argument list.

assert (cond)
sizeof (type)
if (cond) ...
fun(x)

Writing fun (x) is a good way to invite the reader of your code to
regard you as a twit.
 
J

John Gordon

In said:
That was the question, can you think of a single case where somebody
died as a result of an incorrect return value of main()? Can you

That's a very low-level detail, unlikely to be known by anyone who wasn't
directly involved in such an incident. Asking for such information seems
dishonest.
even come up with a far-fetched hypothetical (primarily for amusement
value, of course)?

Imagine a medical device that emits radiation for treatment of cancer.
Imagine that the device determines the amount of radiation to be emitted
by calling a program and inspecting the exit value. One day the called
program exits with an incorrect value and the device emits too much
radiation, killing a patient.
 
B

Bill Reid

/*
Here's a program which enhances a medical X-ray image, essential so
a human expert can analyse the image to see if a disease is present.
*/
Wrong, this is a program that contains numerous basic
programming errors...
int main(int argc, char **argv)
{

Gee, did you forget some stuff?
unsigned char *image;
int width, height;
int err;

if(argc != 3)
{
/* we were called with the incorrect number of arguments. Tell
user how to use program */
printf("Usage: enhanceimage <xrayimage.jpeg> <enahncedoutput.jpeg>
\n");

What's "printf()"? Where did you prototype it?
return EXIT_FAILURE;
}
image = loadjpeg(argv[1], &width, &height);

What's "loadjpeg()"? Where did you prototype it?
if(!image)
return EXIT_FAILURE;
err = enhanceimage(image, width, height);

What's "enhanceimage()"? Where did you prototype it?
if(err != 0)
return EXIT_FAILURE; /* for some reason algorithm to enhance image
fell over */
err = savejpeg(argv[2], image, width, height);

What's "savejpeg()"? Where did you prototype it?
if(err != 0)
return EXIT_FAILURE;

free(image);

Just what do you think you're free'ing here?
/* image loaded, enhanced and saved correctly */
return 0;

}

Now some medical programming person is using a high-level language,
maybe Perl, to dish up the enhanced images to a webserver.
Did you even bother to link the relevant libraries?
Now some medical programming person is cursing your
complete incompetence...
He writes

$enhancedimagename = "temp.jpeg"; # put the enhanced image in a
temporary buffer
$err = system($rawimagename, $enhancedimagename);
if($err == 0)
diplayimage(enhancedimagename);
else
# do something here to indicate that the image held in temp.jpeg is
NOT an enhanced image for the correct patient.
Patient DEAD, and not just because of all YOUR
egregious programming errors...also, couldn't he
have just used "enhanceimage()" in the script if
you had merely compiled THAT as a complete program?
This might not be the best-designed system in the world.

You think? Sheesh...you're the Conrad Murray of medical
programmers...
But it is
correct.

For very small or inverse values of "correct"...
The return provides an easy way to tell the calling script
whether the image was correctly enhanced or not.
This is why I don't like to go to the doctor; the same
kinds of goofballs who can't write a simple Internet
browser that works properly hold my life in their hands...
For implementations of savejpeg() and loadjpeg() read Basic Algorithmshttp://www.malcolmmclean.site11.com/www
Got anything for mpegs? Including the Dolby Digital(TM)
soundtracks? Oh, and something that actually works...
 
B

Bill Reid

That's a very low-level detail, unlikely to be known by anyone who wasn't
directly involved in such an incident.

That's a detail that would be well and fully hashed out in
a wrongful death/malpractice suit, IN PUBLIC COURT...
Asking for such information seems
dishonest.
Not to mention immoral and fattening...no honest decent person
would ever inquire about the exact causes of another person's
death, it's just unseemly...autopsies and coroner's reports
should be banned, FREE THE HONORABLE CONRAD MURRAY!!!

Sheesh...
Imagine a medical device that emits radiation for treatment of cancer.
Imagine that the device determines the amount of radiation to be emitted
by calling a program and inspecting the exit value.  One day the called
program exits with an incorrect value and the device emits too much
radiation, killing a patient.
Well, it's a little amusing, I give you that, but mostly just sad,
like thinking it's "dishonest" to investigate the cause of a person's
death.

What I keep coming away with from this group is how completely,
totally, and absolutely irrational and illogical the regular posters
are; what's really scary is if you think that the poster might
actually try to implement a safe radiological machine as described
above...
 
J

John Gordon

That's a detail that would be well and fully hashed out in
a wrongful death/malpractice suit, IN PUBLIC COURT...

Courts are going to care that a program failed specifically due to an
erroneous return value from main(), and not any of the other million
ways a program can fail?

Since you put such stock in this information being public, please be so
kind as to supply a few examples.
Not to mention immoral and fattening...no honest decent person
would ever inquire about the exact causes of another person's
death, it's just unseemly...autopsies and coroner's reports
should be banned, FREE THE HONORABLE CONRAD MURRAY!!!

Sigh.
 
J

John Gordon

In said:
What I keep coming away with from this group is how completely,
totally, and absolutely irrational and illogical the regular posters
are; what's really scary is if you think that the poster might
actually try to implement a safe radiological machine as described
above...

You explicitly asked for a "far-fetched hypothetical" example.

I gave you one.

You criticised it for being "scary" and unsafe.

Who is being irrational and illogical here?
 
M

Malcolm McLean

What's "printf()"?  Where did you prototype it?
I forgot. Fortunately modern compilers will pick up that error, and
issue a warning. So no one will die as a result.
Did you even bother to link the relevant libraries?
Now some medical programming person is cursing your
complete incompetence...
If the program doesn't link, no executable will be generated at all.
We might have to mess about with linking, but no-one will die as a
result of setting up the linker incorrectly.
Patient DEAD, and not just because of all YOUR
egregious programming errors...also, couldn't he
have just used "enhanceimage()" in the script if
you had merely compiled THAT as a complete program?
The patient can't die because of my personal incompetence. That's the
beauty of doing things the recommended way. The system catches your
mistakes. If you never make a mistake, you can write raw machine code
and the program will always execute correctly. Programming languages
are only needed at all because some people do make mistakes.

Now why can't the Perl programmer just call "enhanceimage" directly?

The reason is that the trivial is important. At some point, the
program is going to have to deal with the rgb colour values that make
up the image. It's going to have to know what format these values are
in, whether they are 24 bit rgb, 32 bit bgra, 3 channle floats, or
whatever. What the program does is provide an interface between a
standard image file format, in this case jpeg (not a good choice for
medical images, but it allows me to plug the jpeg codec in Basic
Algorithms), and enhanceimage. If this isn't done, the Perl programmer
will have to set up an array of bytes. Perl's not the right language
for that sort of thing. it is the right language for manipulating file
names and tieing a jpeg image to an html page describing the patient's
symptoms, the results of his other tests, and so on.
You think?  Sheesh...you're the Conrad Murray of medical
programmers...


For very small or inverse values of "correct"...


This is why I don't like to go to the doctor; the same
kinds of goofballs who can't write a simple Internet
browser that works properly hold my life in their hands...
The trivial is important. If you set up an expectation that programs
which fail return an error condition, then calling programmers may
rely on this condition, without checking the program documentation.
Obviously there should be processes to prevent that from happening,
but the point is that you've slipped past the normal safety controls,
and are relying on the last ditch defence. That might fail, because
the program is behind schedule, it passed its last quality control
check, only a couple of lines of trivial code to enhance the image
have been added. The quality control person decides not to throw the
full q a test suite at it because that means it will be delivered late
and trigger penalty clauses. Inexcusable, but these things can happen.
So the program is run, and works successfully for many years. Then,
one day, the computer runs out of memory and loadjpeg() fails. The
image in test.jpeg is not updated. No error return is given to the
calling Perl program, and the webpage is generated, with an image from
the previous patient. The previous patient was healthy, this one has
the dreaded creeping crud, which can be cured if treated in time, but
is deadly if there is even a few hours delay in administering the
medicinal compound. And that's how void main() can kill somebody.
 
P

Pasquale Frega

Hi all, a simple question about "scanf":
can i set it in manner to read a simple return with nothing or an
escape?
If no, what can i use?
Thanks!
 
B

Bill Reid

You explicitly asked for a "far-fetched hypothetical" example.
I also explicitly said I only wanted it to laugh at...
I gave you one.
You took the bait...SUCKER!!!
You criticised it for being "scary" and unsafe.
Thanks for playing...
Who is being irrational and illogical here?
Obviously the person who is so desperate to prove
the unprovable they come up with laughably silly
hypothetical on a direct command to provide it for
comedy value...
 
B

Bill Reid

Courts are going to care that a program failed specifically due to an
erroneous return value from main(), and not any of the other million
ways a program can fail?
Well, as always, thank you for making my point for me, though
I had to "trick" you into it by posting a simple fact in plain
sight...

Yes, a court is going to be very rigorous in assigning BLAME
for a wrongful death (or in the current high-profile Conrad
Murray case, involuntary manslaughter due to criminal negligence).

In all the goofy attempts to "prove" that an incorrect
main() return value can kill people, the goofballs have
relied on somebody NEGLIGENTLY grabbing some little
piece of software bascially at random and sticking it
willy-nilly into a script and/or system, then expressing
mock amazement when it doesn't do what it was never warranted
to do, and hundreds/thousands/millions/billions of
imaginary people died as a result. (My goofball example
was that NORAD uses a "Hello World" program to determine
whether to launch nuclear missiles; hey, "Hello World"
printed successfully, but the program returns EXIT_FAILURE,
LAUNCH!!!)

Obviously, the people at fault would be the goofballs
who just grabbed some piece of software and ASSUMED it
would work a certain way. On the other hand, if there
were WELL-DEFINED requirements for the operation of
the software that were not met by a sub-contractor,
the sub would be at least partially to blame (there
might be a whole bunch of legal haggling over what
responsibility the prime contractor had for acceptance
testing, but in the fracas you better believe every
single line of offending code and the respective
contracts would be hashed over).

And all of that is exactly what I said is missing,
WELL-DEFINED requirements that the value be set one
way or the other for the great range of programs that
may be written in "C", making EXPECTATIONS and
thus RESPONSIBILITY for any particular value under
any particular condition moot. Now when I TELL
you that I would/have only set EXIT_FAILURE for the great
majority of programs I have written for some type
of uncorrectable memory allocation or similar error,
you are WASTING MY TIME, YOUR PRESUMABLY WORTHLESS
LIFE, AND POSSIBLY THE LIFE OF SOME INNOCENT
PERSON WHO IS THE VICTIM OF YOUR INSANE ASSUMPTIONS
CONTRARY TO MY WELL-DEFINED ASSERTIONS if you try to argue
with me about my choice, or write some stupid unauthorized
script using my program.
Since you put such stock in this information being public, please be so
kind as to supply a few examples.
Anybody who has been following the Conrad Murray trial
is now an expert on EVERY aspect of various anesthetic
and sedative drugs, so why would you make me go out and
gather for you the evidence presented in numerous
lawsuits involving software (some of which I am personally
aware of)? Suffice it to say, all of that kind of
stuff is boring and tedious to the max...
What are you saying, you reject the findings of the
defense expert regarding the levels of unmetabolized
propofol in Michael Jackson's urine at autopsy as being
inconsistent with the prosecution theory of a infusion
drip over several hours based on the nuclear residue
testing in a 1988 study of volunteers receiving a
sedative level dosage of propofol? I will admit
on re-direct the prosecution expert kind of demolished
his testimony...

But yeah, you're right, they never get into trivial
little technical details in courts...
 
P

Pasquale Frega

Your code layout makes my eyes bleed, especially with long lines being
folded (probably by some news software somewhere).

Here's a reformatted version of your program, with some bugs correct.
It's still not perfect (I find that I have to type control-D twice to
exit). Study the changes I've made and the comments I've added. Note
in particular that I've dropped the call to getch(), which is
non-standard.

#include <stdio.h>
#include <math.h>

const long double Pi = 3.14159265358979323846;

float area(float r) {
return r*r*Pi;

}

float perimeter(float r) {
return 2*Pi*r;

}

int main(void) {
/* system("cls"); */
/*
* Why do you want to clear my screen when I run your program?
* And what if I run it on a system that doesn't have a "cls"
* command -- or, worse, that has a "cls" command that does
* something else? If I want to erase my screen, possibly
* destroying information that has nothing to do with your
* program, I can do it myself, thankyouverymuch.
*/

float r=0;
int c;
int items_read;
/* define radius and c variable used to control the behaviour
of program; 'i' needs to clean input buffer*/

printf("This programm calculate Area and Perimenter of a Circle");
do {
printf("\n\nPlease insert radius value (in cm): ");
fflush(stdout);
items_read = scanf("%f", &r); /*input of the radius value*/
if (items_read == 1 && r > 0.0) {
printf("\nArea is cm2: %.2f \n\nPerimeter is cm: %.2f\n",
area(r),
perimeter(r));
}
else {
printf("\nValue must to be a valid number\n");
}

while ((c=getchar()) != '\n' && c != EOF)
;
} while (c != EOF);
return 0;

}

Hi Keith, i have compiled your version, it works but no exactly as i
want; i intend a bit different working. However, thanks!
 
O

osmium

Gordon Burditt said:
*For further details, consult the documentation of the program you
are running.*

In a very real sense, the OS doesn't *use* the return value from
main() much (although it might log it). It provides the information
to applications, so *applications* can use it. The applications
generally know what they are invoking, and can use program-specific
knowledge of what the program they are invoking does (and they need
similar knowledge to correctly invoke the program in the first
place). I am taking a somewhat narrower view of "OS" and a wider
view of "applications" than some may be used to. The kernel, command
interpreters, and such are included, but program development software
like compilers isn't, even if it comes with the OS distribution.

For many programs the binary SUCCESS/FAILURE return is useful. One
that uses it extensively is "make": it stops a program build if a
step fails. There is a syntax to avoid the abort, if desired, for
specific commands. Compilers, assemblers, linkers, etc. return an
appropriate values. GCC's -Werror option lets you decide to stop
builds on warnings if compiling from "make". If a program *aborts*,
say by calling abort(), segmentation violation, manually being
killed, or being interrupted with a character typed from the keyboard
(e.g. ^C), etc., it is given an exit status which is treated as a
failure, so it may still be useful to test the status even if the
program never does exit(EXIT_FAILURE). Shells use this so they
(not the program that crashed) can print "Segmentation violation"
when it happens.

There are also a bunch of little UNIX shell commands like test,
expr, etc. whose primary function is to test something and set the
return code accordingly, so shell scripts can do conditional testing.
This is one thing that makes shell scripts powerful. Shells make
the return code available to shell scripts, which can use it to
take action to notify of failures or recover from them.

Program termination codes go back at least as far as OS/360 JCL,
where "error" status from a compiler indicated that you shouldn't
bother trying to link the resulting object code (if any was produced).

It's unfortunate that UNIX really only had one standard "success"
value. For example, there are a number of "file compare" programs
(cmp, diff, rcsdiff, etc.) which are usable from shell scripts and
other programs that want to give one of 3 possible results:
files compare equal (0)
files compare unequal (1)
comparison failed (e.g. file does not exist, permission denied,
i/o error, etc.) (2)
where the first two are really two different kinds of "success",
but you can't indicate that, so "files unequal" is treated as a
different subtype of failure. File search programs like "grep" and
family also use this return code pattern (match found / no match
found / problems scanning file). I have sometimes wished for two
different symbols:
EXIT_SUCCESS_WITH_PROMOTION_AND_RAISE
and
EXIT_SUCCESS_YOU_GET_TO_KEEP_YOUR_JOB_ANOTHER_WEEK
which denote two different levels of "success".

Many programs will report obvious failures to do what was requested
with EXIT_FAILURE if the OS returns errors like I/O error, permission
error, file does not exist, out of memory, out of disk space, etc.,
and it wasn't able to work around it. Testing the return status
of a "file copy" program should provide an indication of whether
it worked or not, to the extent that the OS reports problems back
to the program.

Programs that need more complex status returned to their invoker
can go beyond the C standard and use the POSIX guarantee of being
able to return 0 - 255. (Other programs have been known to use
standard output or standard error, which the invoker redirects and
parses). Return codes are not a substitute for error messages
giving specific detail (like the name of the file the operation
failed on, what operation was attempted, and what error you got).

There is a whole include file, <sysexits.h> (not specified by any
standard as far as I know, and used extensively by Sendmail), full
of exit return codes for *MAIL TRANSPORT PROGRAMS*. Mail transport
programs try to deliver mail using various methods and use specific
exit codes (forms of failure) beyond those specified by the C
standard, and programs that call them can either treat any value
not equal to 0 or EXIT_SUCCESS as a failure, or they can use specific
knowledge of the failure type to determine remedial action (for
example, retrying the exact same request again later is highly
appropriate for some error classes and pointless for others). The
return codes in <sysexits.h> might be stretched to deal with some
other network-oriented program but they are not useful for programs
in general.
Some examples:
EX_NOHOST - the host specified did not exist.
EX_NOUSER - the user specified did not exist.
EX_USAGE - the command was used incorrectly, e.g. with the wrong
number of arguments, a bad flag, or bad syntax.
EX_TEMPFAIL - a temporary failure, such as not being able to create
a network connection, and the request should be retried.
EX_OSFILE - some system file does not exist, cannot be opened, or
has some sort of error.
EX_IOERR - An error occurred while doing I/O on some file.



It's impossible to come up with a useful set of universal exit
codes. Programs have too much variety. A program "identifylanguage"
given a text file might use exit(54) to mean "Vietnamese". Also,
any blatantly obvious success condition (like "file *DOES* exist")
can be a fatal error. Beyond the class of "success" or "failure",
code meanings will be individual by program (or perhaps group of similar
programs) if you want to use under 128 bits for an exit code.

A hopelessly interactive program (such as an editor) should report
errors to the user via stderr (or a window pop-up, or whatever)
instead of exiting, although having an editor being fed a script
report blatant problems like not being able to open or save files
or running out of memory or disk space via return code (in addition
to an error message) is useful.

A co-worker once decided (well before C89) that a program that
dropped off the end of main() should return 0, rather than random
status. Unfortunately, the unauthorized and untested change he
made also had the effect that "return N;" in main() also returned
0. The change he made affected the cross-compiler, meaning it would
return successful status for anything it tried to compile whether
it worked or not. Someone introduced a typo into a critical part
of the C library for the target system. The result: an overnight
build which *apparently* succeeded, (as opposed to a build which
should have died in half an hour) yet not one program in the whole
build worked. I detected this problem before the resulting build
was actually shipped over to QA - otherwise management might have
killed someone.
 
P

Pasquale Frega

<snip>

your code is still rather poorly laid out.


"write as little as possible" or "write as few lines as possible"?

Sounds like a variant on
"everything should be made as simple as possible, but no simpler"
Some Scientist

I'd say strive for clarity. So don't pack your code really tightly if
it obscures your purpose. Write simple straightforward code. Only
deviate from this if you need (*really* need) the performance or some
other constraint pushes you away from perfect clarity.


I wish I was decended from bears but my wishes don't change the facts.


layout, clarity etc. if your progarm is going to have any sort of
extended lifetime. Unlikely in this case but it's sensible to start
with good habbits.
My stile is my stile, i will try to improve it but it is going to take
its way.
I always will comment my code, if in the future you should read some
my program, it is sure you find all needs to understand and to change
it!
As short, as clear, as well as possible.
 
J

John Gordon

Yes, a court is going to be very rigorous in assigning BLAME
for a wrongful death (or in the current high-profile Conrad
Murray case, involuntary manslaughter due to criminal negligence).

Once the court has determined that the machine had a programming fault
which caused the death, and it it known who was responsible for said
programming fault, the court has enough data to assign blame.

However, you appear to be claiming that the court will go further and will
want to classify the particular nature of the programming fault, i.e.
whether it was an incorrect return value from main, or a floating point
conversion error, or a buffer overrun, or one of many other kinds of
technical errors.

I can't imagine the court would care about that level of detail, as it
makes no difference in the case. The court already knows who is at fault:
MegaMedicalDevicesCorp, the developer and manufacturer of the machine.
What are you saying, you reject the findings of the
defense expert regarding the levels of unmetabolized
propofol in Michael Jackson's urine at autopsy as being

I'm saying that in a fair debate (which is the type I hope we are having),
asking for information which your opponent cannot reasonably know seems
dishonest.

In my opinion, when you asked for specific case details "... where somebody
died as a result of an incorrect return value of main()", you were asking
the impossible. Who would know that sort of detail, aside from someone
actually involved with such an incident? Nobody.
 
I

Ian Collins

My stile is my stile, i will try to improve it but it is going to take
its way.
I always will comment my code, if in the future you should read some
my program, it is sure you find all needs to understand and to change
it!
As short, as clear, as well as possible.

Your style includes a lot of pointless comments, which distract the
reader and would be a pain for a maintenance programmer. Some examples:

/*input of the radius value*/
/*call area perimeter and function*/
/*reset radius value*/

and worst of all:

/*define perimeter function*/

None of your comments expansion why you are doing something.

If you strive for brevity and clarity, such comments are a strong
indicator that you are failing!
 
I

ImpalerCore

Oh great, somebody who knows how computers work, I've been looking
for somebody like that to explain something...


Oh yes, people could die...soooooooo, please explain how a
common OS, such as say, Windows(TM), uses the return value
from main()?  Or for that matter, a TRUE Unix(TM)?  Or any
other OSs that you are an expert on?

And while you're on the subject, how should a computer
expert such as yourself set the return value of main() to be
correct?
Can you define what conditions would cause me to set it one
way or another?  Of course, I'm assuming that since the
ANSI C committee decreed that main() have a specific set
of return values, every computer in the world conforms
to those values and does something useful with them, so
I would have perfect "portability" between platforms
for my "correct" C code, and nobody would die as a result
of my using an incorrect return value...

Also, what's "winmain()"?  I've seen that a lot, returns
something called a "Windows handle", what's up with that?

You know, I've asked these questions here before, but
never received an answer, but I'm sure that's because
there wasn't a computer expert such as yourself to answer
them...

P.S.  Note carefully that I didn't ask if it was OK
to return a value from main() (or any function) when
the function prototype does not have a return value,
and I always use the correct prototype for main(),
just because it's annoying to have the error messages
from the compiler, just like this topic is annoying...

I'm curious about the whole 'int' return type placed on 'main' as
well. The only idea that I can come up with is that since Ritchie
designed C to support the Unix operating system, and the Unix
operating system wanted to implement pipes for inter-program
communication, 'int main(...)' became the de-facto standard to use the
return value in that sense. What's interesting is that there are
other scenarios where returning a value from 'main' makes little to no
sense, like in embedded systems designed to run a single stand-alone
application "forever", with no opportunity for inter-process
communication, and yet 'void main(...)' is ridiculed even though it
seems to have a logical place in some application design domains.

Best regards,
John D.
 
K

Kaz Kylheku

*For further details, consult the documentation of the program you
are running.*

In a very real sense, the OS doesn't *use* the return value from

That's true, but in the C language there is a sense of "use" which
means simply to look at a value (even to just propagate it elsewhere).

An adequate answer to the question is that the OS (or whatever it is that calls
your program) uses the return value in order to establish a termination status
(which is something related to that value, but is not that value).

Other programs then use the termination status.
 
S

Seebs

I'm curious about the whole 'int' return type placed on 'main' as
well. The only idea that I can come up with is that since Ritchie
designed C to support the Unix operating system, and the Unix
operating system wanted to implement pipes for inter-program
communication, 'int main(...)' became the de-facto standard to use the
return value in that sense.

I've not yet heard of an operating system which doesn't have some concept
roughly analagous to a return status.
What's interesting is that there are
other scenarios where returning a value from 'main' makes little to no
sense, like in embedded systems designed to run a single stand-alone
application "forever", with no opportunity for inter-process
communication, and yet 'void main(...)' is ridiculed even though it
seems to have a logical place in some application design domains.

It's not for *actual* freestanding systems -- the C standard only specifies
the type of main for hosted systems. For non-hosted systems, the standard
doesn't even specify where execution starts!

The thing is, it doesn't matter whether or not you run a program forever;
what matters is whether the operating system's startup code is expecting
the call ABI to match that of a function which returns a value. If it does,
then (at least on machines where call ABI cares, which some do), it's
pretty important that the actual function matches what the calling code
expects.

If you aren't in a hosted environment, all bets are off; it may be prohibited
for you to name a function main(), it may be permissible but irrelevant,
who knows? Up to the implementation to document what you do and how you
do it.

-s
 
I

Ian Collins

I'm curious about the whole 'int' return type placed on 'main' as
well. The only idea that I can come up with is that since Ritchie
designed C to support the Unix operating system, and the Unix
operating system wanted to implement pipes for inter-program
communication, 'int main(...)' became the de-facto standard to use the
return value in that sense. What's interesting is that there are
other scenarios where returning a value from 'main' makes little to no
sense, like in embedded systems designed to run a single stand-alone
application "forever", with no opportunity for inter-process
communication, and yet 'void main(...)' is ridiculed even though it
seems to have a logical place in some application design domains.

void main() or any other form (I've used embedded systems where main had
quite lengthy parameter lists!) is perfectly acceptable as an
implementation defined form for main.

int main() {}

Is also permitted by the standard.
 
K

Keith Thompson

Pasquale Frega said:
Hi all, a simple question about "scanf":
can i set it in manner to read a simple return with nothing or an
escape?
If no, what can i use?
Thanks!

If you have a question, please post it as a new article, not as a
followup in an unrelated thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top