項目 foo 中 foo/src/bar/baz.h 使用:
#ifndef FOO_BAR_BAZ_H_ #define FOO_BAR_BAZ_H_ // ... #endif // FOO_BAR_BAZ_H_
// 平台差異
#ifdef _WIN32
#define MYTYPE long
#else
#define MYTYPE float
#endif
// 調試開關
#ifdef DEBUG
printf("device_open(%p)\n", file);
#endif
// 需配合 -DDEBUG 編譯選項
不內聯超過 10 行的函數。
輸入參數在前,輸出參數在後。
PascalCase,變數/函數 snake_case,常數 kConstantName,宏 ALL_CAPSconst、constexprstd::unique_ptr、std::shared_ptr,避免裸 new/delete完整指南:https://google.github.io/styleguide/cppguide.html
自動格式化工具:clang-format 配合 .clang-format 設定檔(Google 風格預設)。