Prev: inheriting a main method
Next: Adding int to a float
From: Jim Janney on 21 Sep 2009 19:56 Jim Janney <jjanney(a)shell.xmission.com> writes: > Thomas Pornin <pornin(a)bolet.org> writes: > >> According to rossum <rossum48(a)coldmail.com>: >>> When coding in C or C++ I use 'register' to hint to the compiler that >>> something might usefully be kept in a place with easy/quick access: >> >> It seems that modern C and C++ compilers tend to ignore such hints. >> The net effect of "register" is now more something like: "punish me >> if I use the '&' operator on that variable". > > This does have some practical value; the compiler can reasonably > assume that a register variable is not aliased. > > FWIW, I think Datalight C was the first PC compiler to do global > dataflow analysis and allocate registers based on that, but the big > players, Borland and Microsoft, were quick to copy it. That would be > somewhere around 1990. I just found an old manual for Datalight 3.0 (yes, I'm a pack rat) and it's copyright 1985-1987. I'm guessing 3.0 was the first one with the global optimizer and it came out in 1987. It compiled K&R C with a few extensions, notably the volatile type specifier. -- Jim Janney
From: Patricia Shanahan on 21 Sep 2009 21:22 Jim Janney wrote: > Thomas Pornin <pornin(a)bolet.org> writes: > >> According to rossum <rossum48(a)coldmail.com>: >>> When coding in C or C++ I use 'register' to hint to the compiler that >>> something might usefully be kept in a place with easy/quick access: >> It seems that modern C and C++ compilers tend to ignore such hints. >> The net effect of "register" is now more something like: "punish me >> if I use the '&' operator on that variable". > > This does have some practical value; the compiler can reasonably > assume that a register variable is not aliased. I don't understand this. It's been a long time since I last worked on a C compiler, but as far as I can remember it was quite easy to detect local variables that did not have the "&" operator applied to them. In what cases would it be difficult for the compiler to detect the lack of aliases for a variable that could be marked "register"? Patricia
From: Jim Janney on 22 Sep 2009 00:18
Patricia Shanahan <pats(a)acm.org> writes: > Jim Janney wrote: >> Thomas Pornin <pornin(a)bolet.org> writes: >> >>> According to rossum <rossum48(a)coldmail.com>: >>>> When coding in C or C++ I use 'register' to hint to the compiler that >>>> something might usefully be kept in a place with easy/quick access: >>> It seems that modern C and C++ compilers tend to ignore such hints. >>> The net effect of "register" is now more something like: "punish me >>> if I use the '&' operator on that variable". >> >> This does have some practical value; the compiler can reasonably >> assume that a register variable is not aliased. > > I don't understand this. It's been a long time since I last worked on a > C compiler, but as far as I can remember it was quite easy to detect > local variables that did not have the "&" operator applied to them. > > In what cases would it be difficult for the compiler to detect the lack > of aliases for a variable that could be marked "register"? > Hmm. Now that you put it that way, I can't think of any. Never mind :-) -- Jim Janney |