我在很多场合看到过用const类型限定符来定义函数:
const int foo (int arg)
Run Code Online (Sandbox Code Playgroud)
这有什么意义?函数的返回值无论如何都无法改变..
Chr*_*oph 13
在C中,它确实无用,编译器可能会发出相应的警告:
$ echo 'const int foo (int arg);' | clang -Weverything -fsyntax-only -xc -
<stdin>:1:1: warning: 'const' type qualifier on return type has no effect
[-Wignored-qualifiers]
const int foo (int arg);
^~~~~~
1 warning generated.
Run Code Online (Sandbox Code Playgroud)