?
=?ISO-8859-1?Q?Martin_J=F8rgensen?=
Hi,
Sorry for asking about something which I might be able to find on
google, but I've looked and looked and apparently I'm too stupid to
figure out how to solve this, because I can't isolate the error
I've been looking here:
http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html
----
1) In the top it says: You must use your C++ compiler when compiling
main() (e.g., for static initialization).
Question: I want my (7000 lines) C program to call a C++-function (to
learn more C++ ofcourse) and I'm using visual studio 2005. Doesn't that
mean I have to make the main.c file to a main.cpp file, in order to
satisfy 1) ???
---
2) I can actually easily call my C++-function as long as it doesn't take
any arguments (the build completes and works). But if I try to add
arguments, from C-main to C++-function, it doesn't work:
--- main.c ---
....
....
output_energy(energy_as_function_of_time, step, double_tmp1,
double_tmp2);
//output_energy(); // <<<<---- this works without arguments.
....
....
--- output_energy.h ---
#ifndef output_energy_H
#define output_energy_H
#include <iostream>
extern "C" void output_energy(double **energy_as_function_of_time,
unsigned long step, double cast_energy, double total_energy);
//void output_energy();
#endif
--- output_energy.cpp ---
#include "output_energy.h"
using namespace std;
//void output_energy() // <<<<--- this works...
void output_energy(double **energy_as_function_of_time, unsigned long
step, double cast_energy)
{
cout << "This works" << endl;
}
The above gives 102+ errors (with main.c - with main.cpp I think I only
get 68 errors):
------ Build started: Project: 2D_full_implicit, Configuration: Debug
Win32 ------
Compiling...
main.c
c:\programmer\microsoft visual studio 8\vc\include\cstdio(25) : error
C2143: syntax error : missing '{' before ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdio(25) : error
C2059: syntax error : ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdio(25) : error
C2143: syntax error : missing '{' before ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdio(25) : error
/...... etc. ..... etc....
/...... etc. ..... etc....
/...... etc. ..... etc....
/...... etc. ..... etc....
c:\programmer\microsoft visual studio 8\vc\include\cstdlib(20) : error
C2059: syntax error : ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdlib(21) : error
C2143: syntax error : missing '{' before ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdlib(21) : fatal
error C1003: error count exceeds 100; stopping compilation
Build log was saved at "file://c:\Documents and
Settings\Dell\Skrivebord\bachelor2006\c_programming\2D_full_implicit\Debug\BuildLog.htm"
2D_full_implicit - 102 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I think I need to convert main.c to main.cpp so I get static
initialization (whatever that means). Is this correct?
I think I get 68 errors with main.cpp because I use malloc() in my
C-program many places... Should I convert all those lines to "new ....
something" since I think malloc() doesn't exist in C++?
Best regards
Martin Jørgensen
Sorry for asking about something which I might be able to find on
google, but I've looked and looked and apparently I'm too stupid to
figure out how to solve this, because I can't isolate the error
I've been looking here:
http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html
----
1) In the top it says: You must use your C++ compiler when compiling
main() (e.g., for static initialization).
Question: I want my (7000 lines) C program to call a C++-function (to
learn more C++ ofcourse) and I'm using visual studio 2005. Doesn't that
mean I have to make the main.c file to a main.cpp file, in order to
satisfy 1) ???
---
2) I can actually easily call my C++-function as long as it doesn't take
any arguments (the build completes and works). But if I try to add
arguments, from C-main to C++-function, it doesn't work:
--- main.c ---
....
....
output_energy(energy_as_function_of_time, step, double_tmp1,
double_tmp2);
//output_energy(); // <<<<---- this works without arguments.
....
....
--- output_energy.h ---
#ifndef output_energy_H
#define output_energy_H
#include <iostream>
extern "C" void output_energy(double **energy_as_function_of_time,
unsigned long step, double cast_energy, double total_energy);
//void output_energy();
#endif
--- output_energy.cpp ---
#include "output_energy.h"
using namespace std;
//void output_energy() // <<<<--- this works...
void output_energy(double **energy_as_function_of_time, unsigned long
step, double cast_energy)
{
cout << "This works" << endl;
}
The above gives 102+ errors (with main.c - with main.cpp I think I only
get 68 errors):
------ Build started: Project: 2D_full_implicit, Configuration: Debug
Win32 ------
Compiling...
main.c
c:\programmer\microsoft visual studio 8\vc\include\cstdio(25) : error
C2143: syntax error : missing '{' before ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdio(25) : error
C2059: syntax error : ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdio(25) : error
C2143: syntax error : missing '{' before ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdio(25) : error
/...... etc. ..... etc....
/...... etc. ..... etc....
/...... etc. ..... etc....
/...... etc. ..... etc....
c:\programmer\microsoft visual studio 8\vc\include\cstdlib(20) : error
C2059: syntax error : ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdlib(21) : error
C2143: syntax error : missing '{' before ':'
c:\programmer\microsoft visual studio 8\vc\include\cstdlib(21) : fatal
error C1003: error count exceeds 100; stopping compilation
Build log was saved at "file://c:\Documents and
Settings\Dell\Skrivebord\bachelor2006\c_programming\2D_full_implicit\Debug\BuildLog.htm"
2D_full_implicit - 102 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I think I need to convert main.c to main.cpp so I get static
initialization (whatever that means). Is this correct?
I think I get 68 errors with main.cpp because I use malloc() in my
C-program many places... Should I convert all those lines to "new ....
something" since I think malloc() doesn't exist in C++?
Best regards
Martin Jørgensen