"kimimaro" <little_cloudie @yahoo.com> writes:
[color=blue]
> Is there anymore methods in exiting your program using pure C language
> other than return 0?[/color]
There is a way:
exit(0);
This function, I think it is deklared in stdlib.h finishes your program,
but be aware of memoryleaks.
Kind regards,
Nicolas
--
| Nicolas Pavlidis | Elvis Presly: |\ |__ |
| Student of SE & KM | "Into the goto" | \|__| |
| pavnic@sbox.tug raz.at | ICQ #320057056 | |
|-------------------University of Technology, Graz----------------|
"kimimaro" <little_cloudie @yahoo.com> wrote in message
news:ca796b76d9 0c60e1d813cf954 9122799@localho st.talkaboutpro gramming.com...[color=blue]
> Is there anymore methods in exiting your program using pure C language
> other than return 0?
>[/color]
you can also have
return EXIT_FAILURE;
return EXIT_SUCCESS;
"Nicolas Pavlidis" <pavnic@sbox.tu graz.at> wrote in message
news:2v8v0pF2he qtgU3@uni-berlin.de...[color=blue]
> "kimimaro" <little_cloudie @yahoo.com> writes:
>[color=green]
> > Is there anymore methods in exiting your program using pure C language
> > other than return 0?[/color]
>
> There is a way:
> exit(0);
>
> This function, I think it is deklared in stdlib.h finishes your program,
> but be aware of memoryleaks.
>[/color]
Most* OS's free the memory when a program has exited so it's not really a
concern over memory leaks, but rather on programming style.
kimimaro wrote:[color=blue]
> Is there anymore methods in exiting your program using pure C language
> other than return 0?[/color]
Yep, #include <stdlib.h> and use exit() and abort() (actually,
don't use abort()...):
Use
exit(0);
exit(EXIT_SUCCE SS);
if your program is terminated due to circumstances you think
okay (job done, help message printed, ...) and
exit(EXIT_FAILU RE);
if something is definitely not okay.
If you want some things done when exiting your program, have
a look at atexit().
Note: Not all environments where you can run programs clean up
the memory, so you should take care of it before calling exit().
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.
bd <bdonlan@gmail. com> writes:
[color=blue]
> kimimaro wrote:
>[color=green]
> > Is there anymore methods in exiting your program using pure C language
> > other than return 0?[/color]
>
> You can use the exit() or abort() functions.[/color]
Edmund Bacon wrote:[color=blue]
> bd <bdonlan@gmail. com> writes:
>[color=green]
>>kimimaro wrote:
>>[color=darkred]
>>>Is there anymore methods in exiting your program using pure C language
>>>other than return 0?[/color]
>>
>>You can use the exit() or abort() functions.[/color]
>
> And don't forget: assert(0);[/color]
Note: The assert()-macro, if "called" with an expression evaluating
to zero, prints an error message and calls abort().
On Mon, 8 Nov 2004 05:21:11 -0500, "Method Man" <a@b.c> wrote in
comp.lang.c:
[color=blue]
>
> "Nicolas Pavlidis" <pavnic@sbox.tu graz.at> wrote in message
> news:2v8v0pF2he qtgU3@uni-berlin.de...[color=green]
> > "kimimaro" <little_cloudie @yahoo.com> writes:
> >[color=darkred]
> > > Is there anymore methods in exiting your program using pure C language
> > > other than return 0?[/color]
> >
> > There is a way:
> > exit(0);
> >
> > This function, I think it is deklared in stdlib.h finishes your program,
> > but be aware of memoryleaks.
> >[/color]
>
> Most* OS's free the memory when a program has exited so it's not really a
> concern over memory leaks, but rather on programming style.
>
> *All that I know of.[/color]
There have been, and still are, a few that don't, or don't always.
The C standard cannot and does not place any requirements on what a
platform might do before or after the execution of a C program. So
the C standard neither requires nor guarantees that an operating
system is able to clean up memory.
Michael Mair <Michael.Mair@i nvalid.invalid> wrote in message news:<2v9efbF2i iv2mU1@uni-berlin.de>...[color=blue]
> Edmund Bacon wrote:[color=green]
> > bd <bdonlan@gmail. com> writes:
> >[color=darkred]
> >>kimimaro wrote:
> >>
> >>>Is there anymore methods in exiting your program using pure C language
> >>>other than return 0?
> >>
> >>You can use the exit() or abort() functions.[/color]
> >
> > And don't forget: assert(0);[/color]
>
> Note: The assert()-macro, if "called" with an expression evaluating
> to zero, prints an error message and calls abort().[/color]
NOTE : what I think is that when we call assert
And if it get the agrumnet as NULL then
Its display the message as we see in the case of the Poiters
when it gets the Zero as an argument. then it Returns the 0
(Exit the program)
Is my knowledge about assert is correct ????? help in correcting
If i am wrong.
ranjeet wrote:[color=blue]
> Michael Mair <Michael.Mair@i nvalid.invalid> wrote in message news:<2v9efbF2i iv2mU1@uni-berlin.de>...
>[color=green]
>>Edmund Bacon wrote:
>>[color=darkred]
>>>bd <bdonlan@gmail. com> writes:
>>>
>>>
>>>>kimimaro wrote:
>>>>
>>>>
>>>>>Is there anymore methods in exiting your program using pure C language
>>>>>other than return 0?
>>>>
>>>>You can use the exit() or abort() functions.
>>>
>>>And don't forget: assert(0);[/color]
>>
>>Note: The assert()-macro, if "called" with an expression evaluating
>>to zero, prints an error message and calls abort().[/color]
>
>
> NOTE : what I think is that when we call assert
> And if it get the agrumnet as NULL then
> Its display the message as we see in the case of the Poiters
> when it gets the Zero as an argument. then it Returns the 0
> (Exit the program)
>
> Is my knowledge about assert is correct ????? help in correcting
> If i am wrong.[/color]
I am sorry, I do not understand what you want to tell me.
Just have a peek at this implementation of assert as my_assert.
I just whipped it up but it should fulfill the basic requirements
for assert. The first five assertions will fail.
Use MY_NDEBUG instead of NDEBUG for switching my_assert off.
If this does not answer your question/complement your
understanding/whatever feel free to ask again.
In article <77c88a3b.04110 90027.60a6641c@ posting.google. com>, ranjeet.gupta@g mail.com (ranjeet) writes:[color=blue]
>
> NOTE : what I think is that when we call assert[/color]
assert is a macro, not a function. It's not called, properly speaking.
It's expanded with argument substitution.
[color=blue]
> And if it get the agrumnet as NULL then[/color]
assert evaluates its argument as an integer expression. NULL is a
macro that evaluates to a null pointer constant. All assert cares
about is the truth value of its argument: assert does nothing if
the argument is non-zero, or if the NDEBUG macro was defined (where
assert.h was included in the current translation unit); otherwise it
writes a message to standard error and calls the abort function.
NULL is not the same thing as zero. NULL will evaluate to false, but
the argument to the assert macro need not be a pointer value.
[color=blue]
> Its display the message as we see in the case of the Poiters
> when it gets the Zero as an argument. then it Returns the 0
> (Exit the program)[/color]
No, it calls the abort function. It does not return anything.
The abort function will cause the program to terminate unless the
SIGABRT signal is being caught and the signal handler does not
return. Whether this counts as "exit[ing] the program" is debatable;
the program stops running, but not necessarily in the same manner as
if the exit function were called. (For example, output streams may
not be flushed.)
In practice, it's often enough to simply think of assert as "test
this condition and kill the program if it's false". The actual
situation, however, is more complicated, and if you're writing
serious C programs it is probably a good idea to understand it.
In article <news:cmqh6p0ln a@news3.newsguy .com>
Michael Wojcik <mwojcik@newsgu y.com> wrote:[color=blue]
>assert is a macro, not a function. It's not called, properly speaking.
>It's expanded with argument substitution.[/color]
[Correct]
[color=blue][color=green]
>> And if it get the agrumnet as NULL then[/color]
>
>assert evaluates its argument as an integer expression. NULL is a
>macro that evaluates to a null pointer constant. ...[/color]
The implication here -- which is also correct -- is that assert(NULL)
does not have to compile.
This is sort of a bug in C89, and is fixed in C99, where the argument
to assert() has type "bool" (from <stdbool.h>; really _Bool). In
C99, assert(NULL) is a valid invocation that -- if NDEBUG is not
defined -- emits a message and calls abort().
[color=blue]
>NULL is not the same thing as zero. NULL will evaluate to false, but
>the argument to the assert macro need not be a pointer value.[/color]
In general, even in C89 implementations , assert(ptr) compiles fine
and does the same thing as it is required to do in C99. But a
careful C89 programmer really should write:
assert(ptr != NULL); /* not just assert(ptr) */
"just in case" the program is ever ported to a C89 compiler that
is particularly picky.
(I think Michael Wojcik knows all of this, but it was not specifically
called out in his article.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
In <cmqjqc12r60@ne ws2.newsguy.com > Chris Torek <nospam@torek.n et> writes:
[color=blue]
>In article <news:cmqh6p0ln a@news3.newsguy .com>
>Michael Wojcik <mwojcik@newsgu y.com> wrote:[color=green]
>>assert is a macro, not a function. It's not called, properly speaking.
>>It's expanded with argument substitution.[/color]
>
>[Correct]
>[color=green][color=darkred]
>>> And if it get the agrumnet as NULL then[/color]
>>
>>assert evaluates its argument as an integer expression. NULL is a
>>macro that evaluates to a null pointer constant. ...[/color]
>
>The implication here -- which is also correct -- is that assert(NULL)
>does not have to compile.
>
>This is sort of a bug in C89, and is fixed in C99, where the argument
>to assert() has type "bool" (from <stdbool.h>; really _Bool).[/color]
Nope, in C99 the argument to assert has scalar type.
[color=blue]
>In C99, assert(NULL) is a valid invocation that -- if NDEBUG is not
>defined -- emits a message and calls abort().[/color]
You're contradicting yourself: if assert expected a bool argument, passing
it (void *)0 would be far from correct: undefined behaviour.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
Currently looking for a job in the European Union
Comment