Re: const qualifier - in declaration, definition or both?
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 18:27:32 +0100
Pietro Cerutti wrote, On 31/08/07 13:57:
Asbjørn Sæbø wrote:Suppose I have a function that takes a pointer as its input, but does
not change what the pointer points to. In that case, the const
qualifier can be used to indicate that the variable pointed to is not
changed. But should this const qualifier be used in the function
declaration, the function definition, or both?
If you don't use it in both you may get warnings or even an error
(depending on the compiler settings):
void nop(const int *i);
void nop(int *i)
{
(void)i;
}
<snip>
The compiler is required to issue a diagnostic (commonly a warning or error) so there is not really a may about it.
--
Flash Gordon
.
- References:
- const qualifier - in declaration, definition or both?
- From: Asbjørn Sæbø
- Re: const qualifier - in declaration, definition or both?
- From: Pietro Cerutti
- const qualifier - in declaration, definition or both?
- Prev by Date: programming languages
- Next by Date: Conversion error
- Previous by thread: Re: const qualifier - in declaration, definition or both?
- Next by thread: Re: const qualifier - in declaration, definition or both?
- Index(es):
Relevant Pages
|