When passing an array as an argument to a function, say, print_foo,
where the function isn't meant to modify the array, it makes perfect
sense to me to make it a const. 

But what about when passing structs, ints, bools, etc? If the function
doesn't need to modify them, what's the standard practice?

I guess an example. (hopefully if I've ERRORED, my intent is still
clear)

struct foo
{
  int x;
  int y;
};

void init(foo &p, const int x, const int y)
{
  p.x = x;
  p.y = y;
}

Do people do that in practice? Is it good practice? 

It feels a little ridiculous to do

void foo_exit(const bool valid)
{
  if(!valid)
    exit(1);

  exit(0);
}

yet

void init(foo &p, const int x, const int y)
{
  if(x = 0)
    do_something_cool();
  p.x = x;
  p.y = y;
}

...

_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders

Reply via email to