Hi,
i have a cpp code which is showing no error if I compile it by the command icc.
But if I compile it by g++, it is showing errors.
I am just confused about this pattern.
If anyone have any idea, please suggest.
yeah both are different compiler. Some of the code will work properly on CC( windows compiler) and the same code will throw compile error in linux.
Main reason being that in the code we might be calling some functions which are specific to windows and the linux might not understand.U can take the example of threading ,if you are using WIN32 threads then it won work on linux, u have to use posix.
that could be one reason, the other reason might be is that his code might be non-standard, and a certain compiler may accept it (this is bad) and the other compiler would pick it up and throw an error (this is good).
So it could be one of many reasons, which is why you should post your code and/or the compiler errors you are getting..
and before you post a wall of code....make sure it's in code tags at least.
Thanks for the suggestions. I am working in Linux only. Actually the code is huge with many subprograms used in it, that is why its not easy to post it here. But I can give you the details of the main error which is as follows:
Suppose I have a subprogram namely "sub.h" and there is a function used in this named as "void fun()".
Now if I want to use the function "fun()" in the main program, I just did it as following
#include<iostream>
#include "sub.h"
using namespace std;
int main(){
fun();
return(0);
}
you will notice that I have not declared the function "fun()" here, which is an error if I compile it by g++, and it goes fine if I do it by icc.
It is something which bothers me about the reliability of compilers.
Compilers have the bad habit of providing the developer with non-standard functions that other compilers feel should be different or not implemented. A great example of this is #pragma once . If your aiming for a flexible project, make sure that your compiler is taking the arguments that enforces strict standards for the language you are using and that abide to them at all costs.
I think it is more likely that you are using the language incorrectly.
In header files you should, in general, only have function prototypes.
There should be a corresponding source file (like "sub.cpp") that defines the body of the function.