TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: William McBrine
from: Roy J. Tellason
date: 2003-08-20 04:06:24
subject: QWK problem(s)

William McBrine wrote in a message to Roy J. Tellason:

-=> Roy J. Tellason wrote to William McBrine <=-

 WM> /* get a little-endian short, return an int */
 WM> unsigned getshort(const unsigned char *x)
 WM> {
 WM>         return ((unsigned) x[1] << 8) + (unsigned) x[0];
 WM> }

 RJT> What's the effect of that "const" in there?

 WM> It indicates to the compiler that the value pointed to by x will
 WM> not be modified by getshort(). So this function can take both const
 WM> and non-const parameters. Without it, one might get a warning when
 WM> calling it with a const parameter.

So you'd use one when the function is called,  to make it match.

 WM> In practice, in this particular context, it doesn't mean much. But
 WM> I try always to add "const" to my * parameters, where possible.

I'm still not clear why that's a good thing to do.  But then,  it's been a
long time since I was studying c seriously...

--- 
* Origin: TANSTAAFL BBS 717-838-8539 (1:270/615)
SEEN-BY: 633/267 270
@PATH: 270/615 150/220 379/1 106/1 2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.