[pisa-src] Re: r2524 - trunk/tools/dhcp/mac2ip.c

  • From: Christof Mroz <christof.mroz@xxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Fri, 08 Apr 2011 11:25:10 +0200

On Fri, 08 Apr 2011 10:23:36 +0200, Christoph Viethen <christoph.viethen@xxxxxxxxxxxxxx> wrote:


+    uint32_t lower_bounds_value;
+    uint32_t upper_bounds_value;
+    uint64_t num_bounds_ips;
+    uint32_t old_ip_value, new_ip_value;

These can be const.

Ummm, alright, I may not be quite awake yet. Can they? I'm writing to them, right? (I got this funny feeling I may be asking *really* stupid questions here. Hmmm, will notice soon, I guess.)

If you write to a location at most once, declaring it as constant is good style: first of all it, serves as documentation. More importantly though, it prevents you from writing to a location by accident. This happens faster than you may think: imagine passing a pointer into a function, which passes it to another function etc. and ten calls later, one function writes to that location. The compiler can spot this for you, given that your usage of const is disciplined enough. Using const never hurts. It also encourages the compiler to inline all those temporaries, without sacrificing readability.

Just google for "const-correctness".

Actually, wait for one of my next checkins, because quite a bit of this will dissolve into little clouds of ... nothing once I'll begin to use standard stuff like htonl() on standard data types.

Sounds good... if you're experimenting and don't want immediate feedback, I suggest working in a branch and requesting a merge afterwards, kinda like in HIPL. While there's no first-class support for branches in SVN, you can use an idiomatic approach: http://svnbook.red-bean.com/en/1.1/ch04s02.html

<mac2ip.py>

Thanks, that looks interesting!

Oops, please ignore that one :) didn't mean to attach it. It's not too useful, just testing something...
--
This is the pisa developer mailing list. Please also subscribe to the main pisa 
list at:
//www.freelists.org/list/pisa

Other related posts: