Skip to content

Commit

Permalink
[C] Add support for alignof and its aliases
Browse files Browse the repository at this point in the history
This was first added in C11 but has since been revised by C23.
It functions like sizeof but returns alignment instead of size.
So it is implemented as an extension of sizeof.
  • Loading branch information
James Buren committed Oct 30, 2024
1 parent 780041a commit 2fc6519
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions C++/C.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ variables:
type_qualifier: 'const|volatile'
compiler_directive: 'inline|restrict|__restrict__|__restrict'
modifiers: '{{storage_classes}}|{{type_qualifier}}|{{compiler_directive}}'
non_func_keywords: 'if|for|switch|while|decltype|typeof|typeof_unqual|sizeof|static_assert|_Static_assert|__declspec|__attribute__'
non_func_keywords: 'if|for|switch|while|decltype|typeof|typeof_unqual|sizeof|alignof|_Alignof|static_assert|_Static_assert|__declspec|__attribute__'

contexts:
main:
Expand Down Expand Up @@ -197,7 +197,7 @@ contexts:
scope: keyword.control.flow.return.c
- match: \b({{control_keywords}})\b
scope: keyword.control.c
- match: \b(sizeof|static_assert|_Static_assert)\b
- match: \b(sizeof|alignof|_Alignof|static_assert|_Static_assert)\b
scope: keyword.operator.word.c

modifiers:
Expand Down
6 changes: 6 additions & 0 deletions C++/syntax_test_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ typeof_unqual(i) dt;
/* ^ punctuation.section.group.begin */
/* ^ punctuation.section.group.end */

static_assert(alignof(int) == 4);
/* ^ keyword.operator.word */

_Static_assert(_Alignof(int) == 4);
/* ^ keyword.operator.word */

static_assert(sizeof(int) == 4);
/* <- keyword.operator.word */

Expand Down

0 comments on commit 2fc6519

Please sign in to comment.