Re: Porting issues: Visual Studio and gcc
On 9???4???, ??????12???32???, Kenneth Porter <shiva.blackl...@sewingwitch.com>
wrote:
Has anyone gathered a list of issues encountered when porting code that
compiles with Visual Studio to gcc or other more strict compilers? (I don't
mean platform-dependent stuff like special keywords. I'm interested in
things I might mis-code thinking they're legal because VS doesn't
complain.)
I have an app developed under VS 2005 (customer requirement) and 2008 and
am recompiling it under gcc, which catches issues that VS missed. Two I've
encountered so far:
VS lets one "forward declare" an enum, which is apparently a language
violation. To fix this, I hoisted all my enum definitions to a common
header instead of forward declaring them.
gcc is a bit noiser when assigning a double to an int (or unsigned),
issuing a warning in those cases. So I'm wrapping those cases in
static_casts.
Are there other issues that others have encountered that I should watch for
when I'm coding under Windows?
{ edits: quoted banner removed. don't quote extraneous material. tia., -mod }
I ported a project from VC9 to GCC 4.3.2 about a week ago. I wrote a
memo about issues I dealt with, but I left it in the office. The
followings are some entries I remembered. Most of them do not relate
to M$ language extensions, and thus can't fix by /Za compiler option.
1. Capital issues.
ex. #include <IOStReAM> is fine under VC(or Windows), not GCC.
2. Do not enter extra spaces.
ex. #include < iostream >
3. Use slashes, not back slashes
ex. #include <../../foo>. Not #include <..\..\foo>
4. We are not arriving C++0x yet, enter a space for the last template
parameter.
ex. foo<bar<int> >. not foo<bar<int>>
5. If a template function is not used, VC won't even check its syntax.
ex. try this:
template <class T>
void foo(){
> 3<
}
int main()
{
return 0;
}
It will be compiled without a complain.
6. A nested type name of a template class needs a explicit "typename"
declaration in standard.
However, VC is somehow too clever in this issue.
ex.
template <class T>
struct Foo
{
typedef std::list<T> foolist;
}
Foo::foolist list; //compiled under VC! of course, we know the
correct statement will be:
//typename Foo::foolist list;
7. Don't use non-const reference for temporary objects.
ex.
Foo getFoo(){return Foo();}
Foo& foo = getFoo(); //compiled under VC!
8. Extra qualifications are not legal...although VC don't agree with
me.
ex.
class Foo{
int Foo::bar(); //compiled under VC...please write just: int bar
();.
};
That's all I recalled so far. Maybe there are more interesting issues.
I'll check my memo :)
------------------------
Best Regards,
Southp Tien.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]