1821245 Members
3060 Online
109632 Solutions
New Discussion юеВ

ANSI/C and C++

 
SOLVED
Go to solution
Leif Halvarsson_2
Honored Contributor

ANSI/C and C++

Hi
I need to port some programs from Solaris to HP-UX. The langusges is ANSI/C and C++. Do I need to buy both a ANSI/C and a C++ compiler or can the C++ be used for ANSI/C too.
8 REPLIES 8
Ceesjan van Hattum
Esteemed Contributor
Solution

Re: ANSI/C and C++

As far as i know, you should be able to compile ansi/c into C++ compiler, but use gcc (see https://www.beepz.com/personal/merijn/ for hpux-port).
Also look at http://gcc.gnu.org/ for precise info: Currently GCC contains front ends for C, C++, Objective C, Fortran, Java, and Ada, as well as libraries for these languages (libstdc++, libgcj,...).

Succes,
Ceesjan
Ravi_8
Honored Contributor

Re: ANSI/C and C++

Hi,

All C programs must compile under C++ compiler,but due to some unforseen errors some C progrmas wouldn't compile. So u need to buy both aC and aC++ compilers
never give up
Wodisch_1
Honored Contributor

Re: ANSI/C and C++

Hi,

...and since some dev-kits enforce the use of HP's own compilers (and not permit GCC/G++ any more), you'll have to use (and buy) both...

FWIW,
Wodisch
H.Merijn Brand (procura
Honored Contributor

Re: ANSI/C and C++

So true so far, but if you only have your own programs that compile and run fine on Solaris, and you are not depending on any HP specific compiler needs, GNU gcc might be the fastest and cheapest solution by far (it's free)

Fetch it from my ITRC site (CeesJan already mentioned it) https:/www.beepz.com/personal/merijn and *READ* the instructions for gcc

Just try it. If all goes well, you don't need to buy any compiler. GNU gcc is very ANSI compliant.

Recent gcc development also made huge improvements for HP's pa-risc architecture, taking away (more or less) the argument that HP-C compiled binaries are much faster than gcc compiled binaries.

Again, just try. It can't harm you
Enjoy, Have FUN! H.Merijn

Re: ANSI/C and C++


The HP-UX C++ compiler can compile C files, too, as has been said before.
However, if you have dependecies on third party libraries or open source stuff, some of them must be compiled with a special compiler, mostly gcc, some with the HP-UX ANSI-C compiler.

So I'd check the dependencies first. E.g. we had to buy the ANSI-C compiler to compile Python and some other open source globalization library.
Jack Tan
Occasional Advisor

Re: ANSI/C and C++

You can *usually* compile ANSI C programs using a C++ compiler. There are some subtle differences that might affect your code. For example, C++ compilers do not have to define __STDC__, since C++ is not a strict superset of C. HP's aC++ compiler does not define __STDC__. Another example is that global "const" values in C have external linkage, whereas they have internal linkage in C++, so they are no longer available outside of the compilation unit.

For more information, see Bjarne Stroustroup's papers on C/C++ compatibility at http://www.research.att.com/~bs/papers.html . (Stroustroup is the father of C++.)

In practice, it's not too bad. A vast majority of the code should compile, and it's not too hard to fix the rest, assuming you've been diligent about using function prototypes, etc.

Jack
A. Clay Stephenson
Acclaimed Contributor

Re: ANSI/C and C++

I've not had any difficulties compiling ANSI C using the aC++ compiler. The only time that you might need both the HP ANSI C compiler and aC++ is if you need to do K & R C, ANSI C, and C++.
If it ain't broke, I can fix that.
Hartmut Lang
Trusted Contributor

Re: ANSI/C and C++

I'm using/porting/installing a lot of open source programs. I never had a need to use HPs aC++ compiler. So far g++ and gcc did the job (including python, perl, ...).

Some of this programs (loaded from the HPUX porting Archiv) come preconfigured for aCC. And it needs some (not too much) work to make them compile with gcc (e.g. using the right options).

About your ANSI/C, C++ problem:
Most compilers (like gcc) come in a way that they have front-ends which call the right compiler, depending on file-suffixes (c++ compiler for .cc files, c compiler for .c files).
So if you have gcc installed you can compile your c++ code with the c++ compiler, the ansi/c code with the c compiler.
And (if you think it makes sense, and you don't expect problems with name-mangling) you can compile your ansi/c code with the c++ compiler.

Hartmut