Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-30-2004, 03:29 AM   #1 (permalink)
cheawick
Regular Contributor
 
cheawick's Avatar
 
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
cheawick is on a distinguished road
Question 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.
cheawick is offline   Reply With Quote
Old 04-30-2004, 04:06 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Old C and C++ :
Code:
#include <stdarg.h>
New C:
Code:
#include <cstdarg>
New C++:
Code:
#include <stdarg>
using namespace std:
Relax. Get a book. Take your time. Ask your questions anytime.
__________________
Valmont is offline   Reply With Quote
Old 04-30-2004, 04:23 AM   #3 (permalink)
cheawick
Regular Contributor
 
cheawick's Avatar
 
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
cheawick is on a distinguished road
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...
cheawick is offline   Reply With Quote
Old 04-30-2004, 02:53 PM   #4 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
Quote:
Originally posted by Valmont
New C:
Code:
#include <cstdarg>
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>
joe_bruin is offline   Reply With Quote
Old 04-30-2004, 03:32 PM   #5 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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
__________________
Valmont is offline   Reply With Quote
Old 05-01-2004, 03:17 AM   #6 (permalink)
cheawick
Regular Contributor
 
cheawick's Avatar
 
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
cheawick is on a distinguished road
[ 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?
cheawick is offline   Reply With Quote
Old 05-01-2004, 08:58 AM   #7 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote
Old 05-01-2004, 07:51 PM   #8 (permalink)
cheawick
Regular Contributor
 
cheawick's Avatar
 
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
cheawick is on a distinguished road
Please forgive my ignorance... What is NG?
cheawick is offline   Reply With Quote
Old 05-01-2004, 08:23 PM   #9 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
NG = newsgroup
__________________
Valmont is offline   Reply With Quote
Old 05-02-2004, 05:37 AM   #10 (permalink)
cheawick
Regular Contributor
 
cheawick's Avatar
 
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
cheawick is on a distinguished road
Alrighty then, I'll go hide in the corner from the obvious now.
cheawick is offline   Reply With Quote
Old 05-02-2004, 08:51 AM   #11 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Relax . This is a codenewbie forum. If I don't appreciate questions by students then I don't belong here .

Anytime.
__________________
Valmont is offline   Reply With Quote
Old 05-03-2004, 12:57 PM   #12 (permalink)
cheawick
Regular Contributor
 
cheawick's Avatar
 
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
cheawick is on a distinguished road
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
cheawick is offline   Reply With Quote
Old 05-03-2004, 05:55 PM   #13 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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/
__________________
Valmont is offline   Reply With Quote
Old 05-05-2004, 04:45 PM   #14 (permalink)
cheawick
Regular Contributor
 
cheawick's Avatar
 
Join Date: Dec 2003
Location: Mary Esther, FL
Posts: 188
cheawick is on a distinguished road
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:
cheawick is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
c simple question problem with switch case if13121 Standard C, C++ 1 10-24-2004 09:43 PM
operate overloading member function in C# sureshkumar_kc MS Technologies ( ASP, VB, C#, .NET ) 2 10-15-2004 02:36 AM
For those who have Learned C from "The C Programming Lanuage" DemosthenesB Standard C, C++ 5 07-13-2003 12:22 AM
edit? anon Lounge 10 11-21-2002 03:02 PM


All times are GMT -8. The time now is 03:54 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting