C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Standards...or just ettiquette Posted by Gregry2 on 3 Feb 2006 at 11:42 PM
Are these things

void main(){}/*declaration of main as void*/

int foo();/*without void in args*/

void a(){
	printf("hi...");
}/* no return statement*/

int main(){
	void* a=malloc(40);/*(I'd personally never do this
	not freed, even though end of program is right here*/
}


really bad? For the last, how about some heap nodes held by static pointers needed for the whole program? Do i have to call a freeing function at the end of a program?

Thats all.
{2}rIng

to TokoG:
I'm actually a high school student :) If you look at my page, I'm only 15...

The classes are the usual...English, History/Geography, some math (Geometry, probably my favorite subject), a science class (sadly Biology, I'd rather have chemistry...), and a pathetic class for Computer...jk, its only Graphics, no fun stuff

My Electives are Video Editing and Band...should have taken Biochemistry...half chemistry at least...oh well...Band was better.

Thats enough about me. Sorry


Report
Re: Standards...or just ettiquette Posted by bilderbikkel on 4 Feb 2006 at 3:01 AM
'The best thing of coding standards is
that there are so many to choose from'
(cited from many)

If you read
Herb Sutter,Andrei Alexandrescu. C++ coding standards:
101 rules, guidelines, and best practices. ISBN: 0-32-111358-6

or the C++ FAQ LITE (http://www.parashift.com/c++-faq-lite/),
you would have the following comments on your code:

:
: void main(){}/*declaration of main as void*/
//Bad style. main is of type int, although many compilers support this.

: int foo();/*without void in args*/
//Great style! (void) is called an 'abomination' by many, 
//of which amonng is Bjarne Stroustrup

: void a(){
: 	printf("hi...");
: }/* no return statement*/
//Great style! void requires no return statement at the end. 
//In the beginning and middle, return can be useful.

: int main(){
: 	void* a=malloc(40);/*(I'd personally never do this
: 	not freed, even though end of program is right here*/
: }
//Bad style! Always free your memory. For C++ programmers it is 
//recommended to use new and delete over malloc and free. Also, 
//for C++ programmers it is even recommended to let objects manage
//resources (like e.g. the std::auto_ptr (see e.g.
//www.codepedia.com/1/CppAutoPtr))


See ya,
bilderbikkel




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.