lkml.org 
[lkml]   [2009]   [Dec]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 0/1] Constify struct address_space_operations for 2.6.32-git-053fe57ac v2
Arjan van de Ven wrote:
> On Mon, 14 Dec 2009 22:25:26 +0100
> Pavel Machek <pavel@ucw.cz> wrote:
>
>> On Mon 2009-12-14 08:00:49, Arjan van de Ven wrote:
>>> On Mon, 14 Dec 2009 12:26:56 +0100
>>> Pavel Machek <pavel@ucw.cz> wrote:
>> I certainly object "constify ops... as much as possible". If it
>> uglifies the code, it should not be done. If it is as simple as adding
>> const to few lines, its probably ok.
>>
>> But .... the patch contained huge load of
>>
>> - int (* resume)()
>> + int (* const resume)()
>>
>> What is that?
>
> the ops stuct instantiation itself should be const.
> the members not so much; that makes no sense.

Consitfying the structure fields prevents direct modifications of runtime
allocated ops structures therefore it gives a strong signal to the programmer
that he's trying to do something undesired (this approach is in fact already
used in the kernel, see: iwl_ops).

There is another benefit in that static but non-const ops structures cannot be
directly modified either, therefore it will be easier to make them const later.

Example:

1 struct a {
2 void (* f)(void);
3 void (* const g)(void);
4 } s;
5
6 void h(void)
7 {
8 struct a *p = &s;
9 s.f = 0;
10 s.g = 0;
11 p->f = 0;
12 p->g = 0;
13 }

gcc -c a.c
a.c: In function 'h':
a.c:10: error: assignment of read-only member 'g'
a.c:12: error: assignment of read-only member 'g'

--
Emese


\
 
 \ /
  Last update: 2009-12-14 23:41    [W:0.211 / U:0.232 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site