Code Comments
Programming Forum and web based access to our favorite programming groups."parag_paul@hotmail.com" wrote:
>
> int main() {
should read "int main(void) {".
> int *p;
> p = (int*)malloc(sizeof(int));
should have no cast. The cast is not needed, and is hiding the
critical error of failing to #include <stdlib.h>
> if (p == NULL) {
> Error("Could not allocate the memory\n");
> Error("Quitting....\n");
> exit(1);
The functions "Error" and "exit" are not declared. Error is not a
standard C function. exit is accessed via #include <stdlib.h>.
The argument '1' for it is not legitimate, the only legal arguments
are 0, EXIT_SUCCESS and EXIT_FAILURE. Again, the EXIT_* values are
declared in <stdlib.h>
> }
Here you are missing a "return 0". main returns an int (same as
exit). Do so.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
Post Follow-up to this messageIn article <8dt5v312qia63jq10oaoubtjj2fseibrje@4ax.com>, >Perhaps because the C standard does not, and cannot, impose >requirements on operating systems. So the C standard neither >guarantees nor even specifies what the result on the platform might be >if a C executable terminates without releasing dynamically allocated >memory. If it can't impose requirements on operating systems, it can't specify what the result might be if a program terminates after releasing dynamically allocated memory. -- Richard -- :wq
Post Follow-up to this messageJoe Wright wrote: > Richard Heathfield wrote: > > Yes, it's inelegant. But why does it increase compilation time? The > time required to read the headers must be too trivial to be > calculated and included in 'compilation time'. Or not? I'm now using #include "stdhdr.h", which includes all 24 C99 headers, and the compilation time is still pretty much zero for an empty program. Total about 3000 lines, compared with some 20000 lines for Windows header files for example. Only problem is, when posting code, I need to pick and choose the include files that are used. Now why didn't something like my stdhdr.h get into the standard? And I think my idea is much more elegant than having having some arbitrary, and slightly different, subset of the 24 headers at the start of every module, to add to the maintenance work. -- Bart
Post Follow-up to this messageNick Keighley wrote:
> On 2 Apr, 08:29, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
> wrote:
>
<snip>
>
> this function seems to do almost nothing. It could give
> odd behaviour if s contained any % symbols. Use
>
> printf "%s\n", s);
rather
printf("%s\n", s);
but better
fprintf(stderr,"%s\n", s);
After all it is supposed to print en error message
Bye, Jojo
Post Follow-up to this messageOn Apr 2, 5:56=A0pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
> Nick Keighley wrote:
>
> =A0<snip>
>
>
>
> rather
> =A0 =A0 =A0 printf("%s\n", s);
> but better
> =A0 =A0 =A0 fprintf(stderr,"%s\n", s);
> After all it is supposed to print en error message
>
> Bye, Jojo
Thank you all,
It was a valuable learning experience. But does including strhdr.h
make the compilation procedure costlier
or the compiler has any optimizations like the
#ifndef __STDHDR.H__
-Parag
Post Follow-up to this messageparag_paul@hotmail.com wrote: > On Apr 2, 5:56_pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de> > wrote: > > Thank you all, > > It was a valuable learning experience. But does including strhdr.h > make the compilation procedure costlier > > or the compiler has any optimizations like the > #ifndef __STDHDR.H__ No standard header includes any other standard header, and yes, your "stdhdrs.h" should probably use the customary include guard.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.