1

I have become somewhat of a const-correctness fanatic when it comes to programming. I've got const's everywhere (where correct of course). Now I've even started const'ing my void return types.

You can't create a void object and therefore you can't assign a value to a void object even if it's const or not, which means the "const" becomes redundant.

So am I const'ing my void return types for nothing?

I hope this isn't too philosophical for Stack Overflow.

TL;DR:

const void Foo( void );

vs

void Foo( void );

Is there any difference?

1 Answers1

4

No, const void is completely meaningless. I'm surprised your compiler doesn't give you a warning, actually. Clang, for instance, told me:

example.cpp:1:1: warning: 'const' type qualifier on return type has no effect
      [-Wignored-qualifiers]
const void Foo( void );
^~~~~~
1 warning generated.
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • Hmm, VC++ doesn't give me any errors. Didn't realize it's the same deal with all return types, though. That's why I couldn't find a duplicate question before I posted. – Andreas Vennström Feb 24 '15 at 22:00