Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: any error in the code
"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


Report this thread to moderator Post Follow-up to this message
Old Post
CBFalconer
04-02-08 01:00 PM


Re: any error in the code
In 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

Report this thread to moderator Post Follow-up to this message
Old Post
Richard Tobin
04-02-08 01:00 PM


Re: any error in the code
Joe 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



Report this thread to moderator Post Follow-up to this message
Old Post
Bartc
04-02-08 01:00 PM


Re: any error in the code
Nick 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



Report this thread to moderator Post Follow-up to this message
Old Post
Joachim Schmitz
04-02-08 01:00 PM


Re: any error in the code
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
parag_paul@hotmail.com
04-03-08 03:07 AM


Re: any error in the code
parag_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.


Report this thread to moderator Post Follow-up to this message
Old Post
santosh
04-03-08 03:07 AM


Sponsored Links




Last Thread Next Thread Next
Pages (4): « 1 2 3 [4]
Search this forum -> 
Post New Thread

C archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 12:59 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.