Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
# Configuration for clang-format to match the existing C/C++ code style
Language: Cpp
BasedOnStyle: LLVM

# Indentation
IndentWidth: 4
TabWidth: 4
UseTab: Never
ContinuationIndentWidth: 4

# Column limit
ColumnLimit: 80

# Brace style
BreakBeforeBraces: Linux

# Function style - return type on its own line
AlwaysBreakAfterReturnType: TopLevelDefinitions

# Pointer and reference alignment - space on both sides is most common
PointerAlignment: Middle
DerivePointerAlignment: false

# Space style
SpaceAfterCStyleCast: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false

# Preprocessor indentation - AfterHash to allow spaces after # for nesting
IndentPPDirectives: AfterHash
PPIndentWidth: 1

# Comment alignment
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
SpacesBeforeTrailingComments: 1

# Line breaks
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false

# Includes
SortIncludes: false

# Bin packing
BinPackParameters: true
BinPackArguments: true
AllowAllParametersOfDeclarationOnNextLine: true

# Alignment
AlignConsecutiveMacros:
Enabled: false
AlignConsecutiveAssignments:
Enabled: false
AlignConsecutiveDeclarations:
Enabled: false

# Macro formatting - don't reformat multi-line macros
AlignEscapedNewlines: Left

# Other
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
ReflowComments: false
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ repos:
rev: v1.0.0
hooks:
- id: sphinx-lint
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
hooks:
- id: clang-format
types_or: [c, c++]
files: ^c/
exclude: ^c/(pow_int\.h|avl\.(c|h)|mt19937/.*)
23 changes: 23 additions & 0 deletions DEVEL-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ How to extend the R API
=======================

Extending the R API requires adding a C wrapper function that converts from R types to C types and export that C function to R. See [`Rmoocore.c`](https://github.com/multi-objective/moocore/blob/main/r/src/Rmoocore.c) and [`init.h`](https://github.com/multi-objective/moocore/blob/main/r/src/init.h)


Code Formatting
===============

C/C++ Code
----------

C/C++ code in the `c/` directory is automatically formatted using `clang-format` via pre-commit hooks.

The formatting style is configured in `.clang-format` and aims to match the existing code style:
- 4-space indentation
- K&R style (function return type on separate line)
- 80-character column limit
- Space on both sides of pointer declarations (e.g., `type * name`)

To manually format C/C++ files:

```bash
clang-format -i c/*.c c/*.h
```

The pre-commit hook will automatically format C/C++ files when you commit changes.
Loading