Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

General Code Guidelines

Wei, Jimmy T edited this pageMar 10, 2023 ·1 revision

We are defining our guidelines to drive the following 5 objectives:

  1. Emphasize KISS – Keep it Simple and Short​ -- Minimize the code you need to explain​
  2. Write clean C++ code​
  3. Use consistent variable and type naming​
  4. Use consistent source code formatting​
  5. Samples should be coded using DPC++ idioms and not directly use DPCT runtime functions unless demonstrating a DPCT workflow.

To make these objectives practical we need to choose specific rules to drive consistency

  • "The C++ Core Guidelines" answer language questions.
  • "Google Coding Style" drives consistent variable and type naming and source formatting.
  • Theclang-format tool with the-style=google option is used to enforce consistent source formatting.clang-format -style=google -i file.cpp

We have found that a few modifications of the default style guidelines are preferred in the samples.

  • Fewer source lines where possible​
  • Useauto for declaring variables if it helps to shorten line length​ and does not obscure the concept being taught
  • Simple scalar types over objects when equivalent​
  • std:: types over user-defined types when equivalent​
  • The DPC++ .parallel_for() over SYCL .parallel_for()​
    • NOTE: to build DPC++ .parallel_for() requires the option-fsycl-unnamed-lambda (default behavior). ​
  • Defining the default queue instead of over-specifying the selector​
  • Namingconst values as variables.
    • Do not use thek prefix onconst value names unless you are defining a "magic constant" which should be emphasized
  • Use\n vsstd::endl, unless an explicit flush is required

Source formatting

  • C++ files have extension .cpp​
  • C++ header files have extension .hpp​
  • Enforce viaclang-format​:
    • clang-format -style=google -i file.cpp

Additional Information on DPC++ topics can be found in the book(pdf):

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp