[PATCH 3/3] posix: New Linux posix_spawn{p} implementation

Paul Eggert eggert@cs.ucla.edu
Sun Feb 28 16:41:00 GMT 2016


Adhemerval Zanella wrote:
> I see using const on complex expression might help compiler
> get logic errors (where the variable is set to a different value)

In that case, you should also put "register" in your local declarations too, 
right?  Something like this:

    register const int prot = PROT_READ | PROT_WRITE;

That way, you are also guarded against errors where later code mistakenly 
attempts to take the address of 'prot'.

You may think I'm joking, but I have worked with programmers who believe in this 
sort of thing, and I have experience with (non-GNU) code using this style. The 
problem with this approach is that the attributes get in the way of reading the 
code. Attributes like 'const' can make sense for globals, but for local 
variables the hassle of maintaining them typically outweighs the meager benefits 
of having them. That's certainly the case for this example, anyway.



More information about the Libc-alpha mailing list