- Be careful with use of lower-case letter and upper-case letter concerning the file names because Unix platforms are case sensitive.
If the name of the file is VSessionManager.h
Bad Code:
#include "vsessionmanger.h"
Good Code:
#include "VSessionManger.h" - Do not use #pragma once. Use #if !defined() #endif
Bad Code:
#pragme once
Goode Code:
#if !defined(__MYHEADER_H__)
#define __MYHEADER_H__
...
#endif - To precise a path for include file, use '/' instead of '\', even on Windows.
Bad Code:
#include "..\CmdInterpreter\CmdInterpreter.h"
Good Code:
#include "../CmdInterpreter/CmdInterpreter.h" - When manipulating string path, do not use '\' as a separator, because the separator can be '/'. You should use the defined variable PATH_SEPARATOR_STR.
Bad Code:
ptr = strrchr(font_path, '\\');
Good Code:
ptr = strrchr(font_path, PATH_SEPARATOR_STR); - Do not declared a variable within a block if you need to use it after this block.
Bad Code:
for( int i = 0; i < nb; i++ ) {…}
...
for( i = 0; i < 10; i++ ) {…}
Good Code:
int i;
for( i = 0; i < nb; i++ ) {…}
...
for( i = 0; i <> - Do not create a function without type.
Bad Code:
toto();
Good Code:
void toto() or int toto(); - Do not use the following CString functions:
- Append - you have to use the += operator
- IsEmpty - you have to do a comparison by using GetSize
- LoadString(HINSTANCE hInstance, UINT nID) - you can use only LoadString(UINT nID)
- Do not use the following CStringArray functions:
- GetCount - you have to use GetSize
- Do not use the following CPoint functions:
- SetPoint - you should use the x and y members
- Do not use the following CSize functions:
- SetSize - you should use the cx and cy members
- Do not use the following CMap functions:
- GetSize - you should use GetCount
- Do not use the following CRect functions:
- MoveToXY
- The code automatically generated by Visual Studio in the Message Map are not correct. You have to remove the "&classname::"
Bad Code:
ON_LBN_SELCHANGE(IDC_LANGUAGE_LIST, &CLanguageSelDlg::OnLButtonDownLanguageList)
Good Code:
ON_LBN_SELCHANGE(IDC_LANGUAGE_LIST, OnLButtonDownLanguageList) - When using DYNAMIC_DOWNCAST we need to make sure we use DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC for the base class and the dereived class. Otherwise, there will be a compile error in unix platforms.
- When called a C method from a C++ method, use the extern C convention.
Bad Code:
toto.h: int myfunction();
toto.c: int myfunction() { return 1; }
toto_called.cpp: void myfunction2() { int i = myfunction(); }
Good Code:
toto.h:
#ifdef __cplusplus
extern "C" {
#endif
int myfunction();
#ifdef __cplusplus
}
#endif
toto.c: int myfunction() { return 1; }
toto_called.cpp: void myfunction2() { int i = myfunction(); }
Sunday, November 4, 2007
Porting Guidelines
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment