c - 指针星位置

标签 c pointers code-formatting gnu-indent

使用 GNU 缩进,有没有办法将“星号”放在类型后面?

例如:

void* foo(int* a)

但将其保留在声明中的 var 附近

int *a, b;

最佳答案

C 标准没有说明将 * 紧跟在 type 之后或 variable name 之前,两者都可以。

int *ptr1, ptr2;/* valid, ptr1 is pointer variable, ptr2 is normal variable */
int* ptr1, ptr2;/* valid, ptr1 is pointer variable, ptr2 is normal variable */

类似地,在函数声明或定义中,例如

void* foo(int* a) { 
/*...*/
}

void* foo(int *a) { /* a is int pointer */ 
/*...*/
}

阅读此内容 Placement of the asterisk in pointer declarations

关于c - 指针星位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50304025/

相关文章:

visual-c++ - 为什么一个指针不能存储另一个指针的地址?

git - 提交到 GIT 之前的代码格式化

剪断一根绳子?

c - 使用指针访问二维数组值

C语法。复制字符串

delphi - 我应该在代码中使用 block 标识符 ("end;")吗?

emacs - 如何在 Emacs 中强制执行最大行长度?

c - C中的指针(指针的值)?

c - 重新分配一个指针数组什么都不做

c - 将结构用于链表与将它们用于点类型变量