|
 |
|
 |
04-30-2004, 03:29 AM
|
#1 (permalink)
|
|
Regular Contributor
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
|
to C or C++
I was bouncing around some of the older threads and noticed that I may be using include file calls wrong. Which also makes me wonder wether I'm actually programming in C when I thought I was using C++.
How can one tell the difference and avoid making a simple mistake a VERY BIG mistake with coding.
|
|
|
04-30-2004, 04:06 AM
|
#2 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Old C and C++ :
Code:
#include <stdarg.h>
New C:
New C++:
Code:
#include <stdarg>
using namespace std:
Relax. Get a book. Take your time. Ask your questions anytime.
__________________
|
|
|
04-30-2004, 04:23 AM
|
#3 (permalink)
|
|
Regular Contributor
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
|
Ah ha! Thank you yet again Valmont! I HAVE been mixing up old and new C++. As for books I have several, I guess I need to check the dates on them.
 It may also help if I just stuck with one book versus squeezing the related sections together... 
|
|
|
04-30-2004, 02:53 PM
|
#4 (permalink)
|
|
LOAD "*",8,1
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
|
Quote:
Originally posted by Valmont
New C:
|
this is wrong. neither the C99 spec (the latest ANSI C standard), nor any standard before it allow this. the standard specifically specifies it the way it has always been:
Code:
#include <stdarg.h>
|
|
|
04-30-2004, 03:32 PM
|
#5 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Ah, perhaps it isn't part of the ansi C but it is now for ansi C++.
C (without the ++) was never my terrain though  . I skipped that part when moving from Pascal to C++. But I knew the "c-part" in front of the headers were related to ANSI and C-something  .
Anyway, here is a bit of reference I used. I remembered I read something similar before.
Quote:
ANSI C++
Standard header files
In ANSI-C++ the way to include header files from the standard library has changed.
The standard specifies the following modification from the C way of including standard header files:
Header file names no longer maintain the .h extension typical of the C language and of pre-standard C++ compilers, as in the case of stdio.h, stdlib.h, iostream.h, etc. This extension h simply disappears and files previously known as iostream.h become iostream (without .h).
Header files that come from the C language now have to be preceded by a c character in order to distinguish them from the new C++ exclusive header files that have the same name. For example stdio.h becomes cstdio .
All classes and functions defined in standard libraries are under the std namespace instead of being global. This not applies to C macros that remain as C macros.
Here you have a list of the standard C++ header files:
<algorithm> <bitset> <deque> <exception> <fstream> <functional> <iomanip> <ios> <iosfwd> <iostream> <istream> <iterator> <limits> <list> <locale> <map> <memory> <new> <numeric> <ostream> <queue> <set> <sstream> <stack> <stdexcept> <streambuf> <string> <typeinfo> <utility> <valarray> <vector>
And here is a list of the C header files included in ANSI-C++ with their new name and their equivalents in ANSI-C:
ANSI-C++ ANSI-C
<cassert> <assert.h>
<cctype> <ctype.h>
<cerrno> <errno.h>
<cfloat> <float.h>
<ciso646> <iso646.h>
<climits> <limits.h>
<clocale> <locale.h>
<cmath> <math.h>
<csetjmp> <setjmp.h>
<csignal> <signal.h>
<cstdarg> <stdarg.h>
<cstddef> <stddef.h>
<cstdio> <stdio.h>
<cstdlib> <stdlib.h>
<cstring> <string.h>
<ctime> <time.h>
<cwchar> <wchar.h>
<cwtype> <wtype.h>
Since now classes and functions of the standard libraries are located within the std namespace we must use the C++ using directive for that these become usable in the same way they were in pre-standard code. For example, to be able to use all the standard classes of iostream we would have to include something similar to this:
#include <iostream>
using namespace std;
that would be equivalent to the old expression
#include <iostream.h>
previous to the standard.
Nevertheless for compatibility with ANSI-C, the use of name.h way to include C header files is allowed. Therefore, both following examples are valid and equivalent in a compiler which fulfills ANSI-C++ specifications:
// ANSI C++ example
#include <cstdio>
using namespace std;
int main ()
{
printf ("Hello World!");
return 0;
}
// pre ANSI C++ example
// also valid under ANSI C++, but deprecated
#include <stdio.h>
int main ()
{
printf ("Hello World!");
return 0;
}
In all the examples of the current version of The C++ tutorial it has been chosen to include the old way because to date is the most compatible format (and also shorter), although if you have a compiler that supports ANSI-C++ standard I recommended you the use of the new format in your programs.
ŠThe C++ Resources Network, 2000 - All rights reserved
|
__________________
|
|
|
05-01-2004, 03:17 AM
|
#6 (permalink)
|
|
Regular Contributor
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
|
[ quote]
Anyway, here is a bit of reference I used. I remembered I read something similar before. [/b][/quote]
Hey Valmont, is there a website or link to keep current on new ANSI C++ standards?
|
|
|
05-01-2004, 08:58 AM
|
#7 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
I don't know about sites. But you can communicate with alt.comp.lang.learn.c-c++ .
This newsgroup deals only with the latest standards. Besides that, you can order the explanations on the latest standards (about $10). But I forgot the link. The NG knows tho. I gotta post myself, but first I'll google a bit.
__________________
|
|
|
05-01-2004, 07:51 PM
|
#8 (permalink)
|
|
Regular Contributor
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
|
Please forgive my ignorance... What is NG?
|
|
|
05-01-2004, 08:23 PM
|
#9 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
NG = newsgroup
__________________
|
|
|
05-02-2004, 05:37 AM
|
#10 (permalink)
|
|
Regular Contributor
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
|
 Alrighty then, I'll go hide in the corner from the obvious now. 
|
|
|
05-02-2004, 08:51 AM
|
#11 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Relax  . This is a code newbie forum. If I don't appreciate questions by students then I don't belong here  .
Anytime.
__________________
|
|
|
05-03-2004, 12:57 PM
|
#12 (permalink)
|
|
Regular Contributor
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
|
I didn't mean it like that, I just had one of those "DUH!" moments. The typical brain fart that happens when you are distracted.:-P
|
|
|
05-03-2004, 05:55 PM
|
#13 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Shall I give you an idea?
How about downloading an e-book from the internet and start following a C++ tutorial? Did you install a DevShed CPP program yet?
Here is a nice starter: http://www.cplusplus.com/doc/tutorial/
__________________
|
|
|
05-05-2004, 04:45 PM
|
#14 (permalink)
|
|
Regular Contributor
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
|
Hi Valmont!
Yes I did download the DevC++4 and the other URL is one I have visited before. I'm now going back and checking my older programs to see if I mixed C and C++ there also.
I believe you have made more sense than you can ever realize to me in those last posts.
:rock:Jam  On:rock:
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 03:54 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|