bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#35062: [PATCH v3 2/3] constify a bit of xterm.c


From: Paul Eggert
Subject: bug#35062: [PATCH v3 2/3] constify a bit of xterm.c
Date: Fri, 19 Apr 2019 17:31:38 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

I'd rather not use 'const' on locals. Let me tell you a story as to why.

I once worked with someone who insisted on using the 'register' keyword on every C local variable that was never taken the address of, on the grounds that this meant the reader could easily see that the variable could never be modified indirectly via a pointer and that this made the code easier to read because you didn't need to worry about aliasing.

I disagreed then, and still disagree. Saying 'register' nearly all the time clutters up the code, and the cost is not worth the benefit in C. It's pretty easy for a human reader to determine whether a local variable is taken the address of somewher in its function. (If it's hard, then write an Elisp function that will tell you. :-) In hindsight, perhaps C should have been designed so that 'register' was the default for local variables, and that one needed a special word to say "watch out! this variable might have its address taken!"; but the ship has sailed.

'const' is like 'register' in this respect. Putting 'const' nearly everywhere clutters C code. It's pretty easy for a human reader to determine whether a local variable is modified (if it's hard, write an Elisp function :-). In hindsight, perhaps C should have been designed so that 'const' was the default for local variables; but the ship has sailed there too.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]