C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

C program is standard C++ program?
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
strutsng@gmail.com
Guest





PostPosted: Sat Oct 22, 2005 7:58 am    Post subject: C program is standard C++ program? Reply with quote



I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

In a C++ program, we can use standard C libraries. However, we cannot
use C++ libraries inside C program.

Please advise. thanks!!

Back to top
Jonathan Mcdougall
Guest





PostPosted: Sat Oct 22, 2005 8:16 am    Post subject: Re: C program is standard C++ program? Reply with quote



[email]strutsng (AT) gmail (DOT) com[/email] wrote:
Quote:
I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

No.

void template()
{
}

int main()
{
template();
}

is a valid C, but invalid C++. Check your favorite textbook (you do
have one, don't you?) or google for more informations on C and C++
incompatibilities.

Quote:
In a C++ program, we can use standard C libraries. However, we cannot
use C++ libraries inside C program.

It depends on what you call a "C++ library".

extern "C"
{
void f();
}

Is this a "C++ library"? If yes, then a C program can use some C++
libraries. Your question is too vague.


Jonathan


Back to top
Marcus Kwok
Guest





PostPosted: Sat Oct 22, 2005 8:22 am    Post subject: Re: C program is standard C++ program? Reply with quote



In comp.lang.c++ [email]strutsng (AT) gmail (DOT) com[/email] wrote:
Quote:
I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

In most cases, yes, but there are a few cases where this is not true.
For example, if a C program declares identifiers that are now C++
keywords but that are not C keywords. TC++PL has a section on this
topic.

Quote:
In a C++ program, we can use standard C libraries. However, we cannot
use C++ libraries inside C program.

True.

--
Marcus Kwok

Back to top
Marcus Kwok
Guest





PostPosted: Sat Oct 22, 2005 8:24 am    Post subject: Re: C program is standard C++ program? Reply with quote

Quote:
In comp.lang.c++ [email]strutsng (AT) gmail (DOT) com[/email] wrote:
In a C++ program, we can use standard C libraries. However, we cannot
use C++ libraries inside C program.

In comp.lang.c++ Marcus Kwok <ricecake (AT) gehennom (DOT) net> wrote:
Quote:
True.

After reading Jonathan's post, I will amend this to mean the standard
C++ libraries, e.g., the STL.

--
Marcus Kwok

Back to top
Heinz Ozwirk
Guest





PostPosted: Sat Oct 22, 2005 8:27 am    Post subject: Re: C program is standard C++ program? Reply with quote

<strutsng (AT) gmail (DOT) com> schrieb im Newsbeitrag
news:1129967908.534965.159700 (AT) g14g2000cwa (DOT) googlegroups.com...
Quote:
I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

No. Not every C program is also a valid C++ program. "new", "class" or
"template" to name only a few, are valid identifiers in C, but they are
reserved words in C++. So any C program using one of these identifiers is
not a valid C++ program. Also

void foo();
int main() { foo(1); }

is legal in C, but not in C++

Quote:
In a C++ program, we can use standard C libraries. However, we cannot
use C++ libraries inside C program.

Just that you can use C libraries in C++ does not imply that C is a subset
of C++. You can also use Pascal or Fortran libraries in C++, but that is no
reason to think that every Pascal or Fortran program is also a C++ program.

Heinz



Back to top
Alex Vinokur
Guest





PostPosted: Sat Oct 22, 2005 8:37 am    Post subject: Re: C program is standard C++ program? Reply with quote

[email]strutsng (AT) gmail (DOT) com[/email] wrote:
Quote:
I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?
[snip]


int main()
{
char a[3] = "foo";
return 0;
}

It is legal in C, but not in C++.

Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn


Back to top
Emmanuel Delahaye
Guest





PostPosted: Sat Oct 22, 2005 9:26 am    Post subject: Re: C program is standard C++ program? Reply with quote

[email]strutsng (AT) gmail (DOT) com[/email] a écrit :
Quote:
I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

No, it's not

http://david.tribble.com/text/cdiffs.htm

Unfortunately, this link seems to be down at the moment.
Maybe, more information here :

david at tribble dot com

Quote:
In a C++ program, we can use standard C libraries. However, we cannot
use C++ libraries inside C program.

Correct.

--
C is a sharp tool

Back to top
Martin Ambuhl
Guest





PostPosted: Sat Oct 22, 2005 10:04 am    Post subject: Re: C program is standard C++ program? Reply with quote

[email]strutsng (AT) gmail (DOT) com[/email] wrote:
Quote:
I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

It is a grossly erroneous statement. C and C++ are different languages.
There are countless C programs that are not C++ programs.

Back to top
John Carson
Guest





PostPosted: Sat Oct 22, 2005 10:51 am    Post subject: Re: C program is standard C++ program? Reply with quote

"Martin Ambuhl" <mambuhl (AT) earthlink (DOT) net> wrote

Quote:
strutsng (AT) gmail (DOT) com wrote:
I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

It is a grossly erroneous statement. C and C++ are different
languages. There are countless C programs that are not C++ programs.

"C++ was developed from the C programming language and, with few exceptions,
retains C as a subset."
Bjarne Stroustrup, The C++ Programming Language, 3rd ed., p. 8.


--
John Carson


Back to top
Michael Mair
Guest





PostPosted: Sat Oct 22, 2005 11:23 am    Post subject: Re: C program is standard C++ program? Reply with quote

John Carson wrote:
Quote:
"Martin Ambuhl" <mambuhl (AT) earthlink (DOT) net> wrote in message
news:F8o6f.19590$q1.609 (AT) newsread3 (DOT) news.atl.earthlink.net

[email]strutsng (AT) gmail (DOT) com[/email] wrote:

I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

It is a grossly erroneous statement. C and C++ are different
languages. There are countless C programs that are not C++ programs.

"C++ was developed from the C programming language and, with few
exceptions, retains C as a subset."
Bjarne Stroustrup, The C++ Programming Language, 3rd ed., p. 8.

This may have been the intent; however, Martin's statement still is
true as C++ semantics differ from C89 in many points.
C99 introduced enough additional non-trivial differences which cannot
be easily overcome. The C standard does not make any claim w.r.t. C++
compatibility, even though there may be a rationale saying exactly
that. I do not own the C++ standard, so I cannot say anything from
this point of view.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.

Back to top
John Carson
Guest





PostPosted: Sat Oct 22, 2005 11:58 am    Post subject: Re: C program is standard C++ program? Reply with quote

"Michael Mair" <Michael.Mair (AT) invalid (DOT) invalid> wrote

Quote:
John Carson wrote:
"Martin Ambuhl" <mambuhl (AT) earthlink (DOT) net> wrote in message
news:F8o6f.19590$q1.609 (AT) newsread3 (DOT) news.atl.earthlink.net

[email]strutsng (AT) gmail (DOT) com[/email] wrote:

I want if "a C program is a standard C++ program, but not vice
versa" is a correct statement?

It is a grossly erroneous statement. C and C++ are different
languages. There are countless C programs that are not C++
programs.

"C++ was developed from the C programming language and, with few
exceptions, retains C as a subset."
Bjarne Stroustrup, The C++ Programming Language, 3rd ed., p. 8.

This may have been the intent; however, Martin's statement still is
true as C++ semantics differ from C89 in many points.

The statement that "C++ ... with few exceptions retains C as a subset" is
not a statement of intent but a description of the relationship between the
two languages, albeit one that seems to be directed at C89. I quote again:

"With minor exceptions, C++ is a superset of C. Most differences stem from
C++'s greater emphasis on type checking. Well-written C programs tend to be
C++ programs as well."
Bjarne Stroustrup, The C++ Programming Language, 3rd ed., Appendix B,
Compatibility, p. 816.

Quote:
C99 introduced enough additional non-trivial differences which cannot
be easily overcome.

That does indeed add to the incompatibility, though there are efforts
underway to bring the two languages closer together, particularly by adding
C99 stuff to C++.

Quote:
The C standard does not make any claim w.r.t. C++
compatibility, even though there may be a rationale saying exactly
that. I do not own the C++ standard, so I cannot say anything from
this point of view.

Section 1.1/2 of the C++ standard:

"C++ is a general purpose programming language based on the C programming
language as described in ISO/IEC 9899:1990 Programming languages - C (1.2).
In addition to the facilities provided by C, C ++ provides additional data
types, classes, templates, exceptions, namespaces, inline functions,
operator overloading, function name overloading, references, free store
management operators, and additional library facilities."

Annex C (appropriately enough) of the C++ standard deals with the
relationship between C and C++, noting the areas of incompatibility.

--
John Carson


Back to top
Rolf Magnus
Guest





PostPosted: Sat Oct 22, 2005 1:22 pm    Post subject: Re: C program is standard C++ program? Reply with quote

John Carson wrote:

Quote:
"Well-written C programs tend to be C++ programs as well."
Bjarne Stroustrup, The C++ Programming Language, 3rd ed., Appendix B,
Compatibility, p. 816.

I tend to disagree. In C, dynamic memory is usually allocated with malloc or
other functions that return a pointer to void. That pointer gets converted
implicitly into the target type in C, and a cast should be avoided in a
"well-written C program". However, in C++, it doesn't compile without a
cast. Dynamic memory is something that is used quite often, so I'd say that
most well-written C programs are not C++ programs and would need lots of
changes (in all places where dynamic memory is allocated).


Back to top
John Carson
Guest





PostPosted: Sat Oct 22, 2005 1:59 pm    Post subject: Re: C program is standard C++ program? Reply with quote

"Rolf Magnus" <ramagnus (AT) t-online (DOT) de> wrote

Quote:
John Carson wrote:

"Well-written C programs tend to be C++ programs as well."
Bjarne Stroustrup, The C++ Programming Language, 3rd ed., Appendix B,
Compatibility, p. 816.

I tend to disagree. In C, dynamic memory is usually allocated with
malloc or other functions that return a pointer to void. That pointer
gets converted implicitly into the target type in C, and a cast
should be avoided in a "well-written C program". However, in C++, it
doesn't compile without a cast. Dynamic memory is something that is
used quite often, so I'd say that most well-written C programs are
not C++ programs and would need lots of changes (in all places where
dynamic memory is allocated).

Your point is covered in the preceding sentence: "Most differences stem from
C++'s greater emphasis on type checking." But I guess that this preceding
sentence somewhat gives the lie to the one that follows, so strictly
speaking you are probably right that "most well-written C programs are not
C++ programs".

I am more sceptical about your claim that they would need "lots of changes".
Well written C programs will hide most of the malloc calls inside
initialization functions --- manual equivalents of constructors --- and the
number of these shouldn't be very large.

--
John Carson


Back to top
Michael Mair
Guest





PostPosted: Sat Oct 22, 2005 2:08 pm    Post subject: Re: C program is standard C++ program? Reply with quote

John Carson wrote:
Quote:
"Michael Mair" <Michael.Mair (AT) invalid (DOT) invalid> wrote in message
news:3rulqfFl484oU1 (AT) individual (DOT) net

John Carson wrote:

"Martin Ambuhl" <mambuhl (AT) earthlink (DOT) net> wrote in message
news:F8o6f.19590$q1.609 (AT) newsread3 (DOT) news.atl.earthlink.net

[email]strutsng (AT) gmail (DOT) com[/email] wrote:

I want if "a C program is a standard C++ program, but not vice
versa" is a correct statement?

It is a grossly erroneous statement. C and C++ are different
languages. There are countless C programs that are not C++
programs.

"C++ was developed from the C programming language and, with few
exceptions, retains C as a subset."
Bjarne Stroustrup, The C++ Programming Language, 3rd ed., p. 8.

This may have been the intent; however, Martin's statement still is
true as C++ semantics differ from C89 in many points.

The statement that "C++ ... with few exceptions retains C as a subset" is
not a statement of intent but a description of the relationship between the
two languages, albeit one that seems to be directed at C89. I quote again:

"With minor exceptions, C++ is a superset of C. Most differences stem from
C++'s greater emphasis on type checking. Well-written C programs tend to be
C++ programs as well."
Bjarne Stroustrup, The C++ Programming Language, 3rd ed., Appendix B,
Compatibility, p. 816.

Hmmm, my C code tends to look quite different from my C++ code.
Things I find quite acceptable in C are not acceptable in C++
where better solutions to address certain problems exist.

Apart from the different semantics of void* and ambiguities w.r.t.
overloaded functions, there are better ways to perform explicit
type conversions in C++ than the good old C-style cast.


Quote:
C99 introduced enough additional non-trivial differences which cannot
be easily overcome.

That does indeed add to the incompatibility, though there are efforts
underway to bring the two languages closer together, particularly by adding
C99 stuff to C++.

Yes, AFAIR there were a couple of good articles by B.Stroustrup in CUJ
about the areas where this is easily possible and where in his opinion,
either C++ or C should change semantics. They may still be available
online.


Quote:
The C standard does not make any claim w.r.t. C++
compatibility, even though there may be a rationale saying exactly
that. I do not own the C++ standard, so I cannot say anything from
this point of view.

Section 1.1/2 of the C++ standard:

"C++ is a general purpose programming language based on the C programming
language as described in ISO/IEC 9899:1990 Programming languages - C (1.2).
In addition to the facilities provided by C, C ++ provides additional data
types, classes, templates, exceptions, namespaces, inline functions,
operator overloading, function name overloading, references, free store
management operators, and additional library facilities."

Annex C (appropriately enough) of the C++ standard deals with the
relationship between C and C++, noting the areas of incompatibility.

Thank you for the information :-)


Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.

Back to top
Branimir Maksimovic
Guest





PostPosted: Sat Oct 22, 2005 2:48 pm    Post subject: Re: C program is standard C++ program? Reply with quote


<strutsng (AT) gmail (DOT) com> wrote

Quote:
I want if "a C program is a standard C++ program, but not vice versa"
is a correct statement?

In a C++ program, we can use standard C libraries.

No we can't

extern "C"{
void strcpy(char* restrict , const char* restrict);
}

Standard C++ compiler should spit error.
Only non standard C++ compiler with appropriate
extensions can use standard C libraries.

However, we cannot
Quote:
use C++ libraries inside C program.

Yes we can
extern "C" void myfunc(int){ MyClass o; } // defines C function
// that can be called from C

Greetings, Bane.



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.