Advertisement

C or C++?

Started by April 11, 2001 02:38 PM
75 comments, last by Chronoslade 23 years, 10 months ago
You can fake the default parameters (they''re not worth the effort though, and don''t fit well in modular or procedural programs). And, like I said, "really complex" macros. I''m not going to deny they are useful . Although they''d be more useful if MSVC would let me put the in .cpp/.h files so that I don''t require halfway complete recompiles just to change them...

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
Like I said before from what I have read and heard it’s all comes down to your choice which one your more comfortable with. But what gets me, isn't the syntax for C++ and C the same and also the keywords used in C++ are used in C except for new and delete? I haven't used C so I am completely uninformed on that!

Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!

Resist Windows XP's Invasive Product Activation Technology!

Edited by - MARS_999 on April 18, 2001 7:17:14 PM
Advertisement
my advice in general is that programmers should learn C then Cpp and use both as a combination later. first step is structured programming, then modular programming and finally object orientated programming. and this is the way they teach you at school and university.
there is absolutely no obvious reason why to learn it the other way round!
Cpp is just an extension of C. its not literally anoter or own language. take away C features from Cpp... whatya got then? lol!
learn and use both and take Cpp funcionalities to solve specific problems in case.

by the way there seem to be so many ppl out there who claim to do programming in Cpp and think they are disregarding and not using C. but in fact they arent aware that they use C all the time. those ones are dumbf**ks. :-p sorry
Sorry about to burst your bubble but at my University they teach in CSC 150: Principles of Programming they use C++. You can take C but its a higher level course. All the CSC 150, 250, and 251 are C++ based. C is only one or two course class. They teach the basics in C++ like loops and if else construction. They don''t touch classes till 251 from what I am seeing. I am finishing up 150 and haven''t seen classes yet. I think they might teach structs before class is out but who knows. They use c++ objects like cout, cin, ofstream, and ifstream. I see people talk about C''s bad points like malloc and how it can produce memory leaks? This is over my head still so I can''t complement on it yet. :-)

Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!

Resist Windows XP''s Invasive Product Activation Technology!
quote:
Original post by MARS_999
I see people talk about C''s bad points like malloc and how it can produce memory leaks?


C''s "malloc" == C++''s "new"
C''s "free" == C++''s "delete"

They''re the same thing. MSVC actually just turns new into malloc and delete into free. The only way they cause memory leaks is if you''re lazy and forget to call the appropriate release thing. They always produce the same assembly. Just to prove it to you:

Delete.cpp
  /****delete.cxx - defines C++ delete routine**       Copyright (c) 1990-1998, Microsoft Corporation.  All rights reserved.**Purpose:*       Defines C++ delete routine.********************************************************************************/#ifndef _DEBUG#include <cruntime.h>#include <malloc.h>#include <new.h>void operator delete( void * p ){    free( p );}#endif  /* _DEBUG */  


New.cpp
  /****new.cxx - defines C++ new routine**       Copyright (c) 1990-1998, Microsoft Corporation.  All rights reserved.**Purpose:*       Defines C++ new routine.********************************************************************************/#include <cruntime.h>#include <malloc.h>#include <new.h>#include <stdlib.h>#ifdef WINHEAP#include <winheap.h>#else  /* WINHEAP */#include <heap.h>#endif  /* WINHEAP */void * operator new( unsigned int cb ){    void *res = _nh_malloc( cb, 1 );    return res;}  


Hmm...

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
*sigh* It''s just like I said - people often confuse ignorance with personal preference.


quote:
Original post by Anonymous Poster

Cpp is just an extension of C. its not literally anoter or own language. take away C features from Cpp... whatya got then? lol!



C++ is another language, with a modified grammar and new functionality. Not everything that is legal in C can be done in C++; however, most of those things lend themselves more to programming mistakes than productive coding, so that is why they were left out of C++.


quote:
Original post by Anonymous Poster

by the way there seem to be so many ppl out there who claim to do programming in Cpp and think they are disregarding and not using C. but in fact they arent aware that they use C all the time. those ones are dumbf**ks. :-p sorry



C++ is not C. People who use C++ do not use C, only a modified copy of it. Features were added to C++ because they are useful by nearly everyone at one time or another and help to solve some of the problems associated with C.
Advertisement
quote:
Original post by Null and Void

They''re the same thing.



They can be used to accomplish the same thing, but they are not the same. (I think this is what you meant.)

C''s malloc works with untyped memory, so it handles alignment issues for you. If you want to work with "untyped" or "raw" memory in C++ with operator new, you must handle the alignment yourself, instead of blindly allocating char arrays.

Although, if you want to manage objects at a lower-level, you might want to look at using the standard allocator, which properly aligns the memory for your type and can construct/destroy elements manually - using placement (read: custom) new.

This topic is closed to new replies.

Advertisement