A Journey 2 Eternity

Porting Guidelines

Posted on: November 26, 2007

1. 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”

2. Do not use #pragma once. Use #if !defined() #endif

Bad Code:
#pragme once

Goode Code:
#if !defined(__MYHEADER_H__)
#define __MYHEADER_H__

#endif

3. 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”

4. 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);

5. 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 < count; i++) {…}

6. Do not create a function without type.

Bad Code:
toto();

Good Code:
void toto() or int toto();

7. Do not use the following CString functions:
i) Append – you have to use the += operator
ii) IsEmpty – you have to do a comparison by using GetSize
iii) LoadString(HINSTANCE hInstance, UINT nID) – you can use only LoadString(UINT nID)

8. Do not use the following CStringArray functions:
GetCount – you have to use GetSize

9. Do not use the following CPoint functions:
SetPoint – you should use the x and y members

10. Do not use the following CSize functions:
SetSize – you should use the cx and cy members

11. Do not use the following CMap functions:
GetSize – you should use GetCount

12. Do not use the following CRect functions:
MoveToXY

13. 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)

14. 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.

15. 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(); }

Advertisements
Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Categories

November 2007
M T W T F S S
    Dec »
 1234
567891011
12131415161718
19202122232425
2627282930  

Blog Stats

  • 27,491 hits
%d bloggers like this: