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

  • From: Christoph Viethen <christoph.viethen@xxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Fri, 08 Apr 2011 19:42:54 +0200

Hi,

On Apr 8, 2011, at 11:25 AM, Christof Mroz wrote:

> 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.

I guess I really should rephrase my question:

"mac2ip.c: In function ‘adjust_ip_to_bounds’:
mac2ip.c:263: error: assignment of read-only variable ‘lower_bounds_value’
mac2ip.c:264: error: assignment of read-only variable ‘upper_bounds_value’
mac2ip.c:265: error: assignment of read-only variable ‘num_bounds_ips’
mac2ip.c:268: error: assignment of read-only variable ‘old_ip_value’
mac2ip.c:271: error: assignment of read-only variable ‘new_ip_value’"

So how do you suggest using "const", if for every variable in that function 
that I could make const I get these errors?

It's not like I didn't try. :-)

> Just google for "const-correctness".

Thanks, I actually know the concept. But somehow, seems like I still need to 
find a way to convince my friend the compiler how to permit writing "at most 
once" to these locations. Seems that right now it will not permit writing at 
all. (Still feeling somewhat stupid!)

>> 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

No worries. I'm just trying to check in what's closely related, one check-in at 
a time, trying to prevent too much of unrelated stuff to go in. Unfortunately, 
there's not really a good way of indicating the ideas one has in mind for the 
next few changes, so there's bound to be some comments which I then will have 
to answer along the lines of "thanks a lot, thought of that, was planning to do 
that anyway". But, please don't let that keep you from sending your feedback! 
Always welcome, and always good to have additional sets of eyes looking at my 
code to see those edges that I don't.


Cheers,

  Christoph

-- 
 viethen@xxxxxxxxxxxxxxxxx

--
This is the pisa developer mailing list. Please also subscribe to the main pisa 
list at:
//www.freelists.org/list/pisa

Other related posts: