A real example of an error caused by an identifier, starting with an underscore

There is a rule according to which identifiers in C or C ++ cannot be defined or used, which begin with an underscore followed by capital, for example. _Foo . This is because these identifiers are reserved by the compiler and thus may interfere with some compiler code and lead to undefined behavior.

Although this rule is well known and accepted by many coding standards, I have never seen a real life situation where this rule could have prevented a lot of damage.

Does anyone know a real example of a violation of this rule? EDIT: I am talking about code that compiles and links perfectly, but because of this it exhibits unexpected behavior.

+5
source share
1 answer

I worked on a system where our application code had a _bind() function (for binding host variables in SQL statements) that was not made static, so it was publicly available.

In one audit of (at least) one O / S (I forgot that it was in the last millennium), the system provided the _bind() function, which - surprise, surprise - had a different interface and performed a different task (binding sockets to IP addresses or so). When the application code was associated with the system library, the system library code completed the call to our _bind() function when trying to establish network connections. Everything has developed well.

We either renamed the function or made it static (or both), and the problem disappeared. Modern shared libraries minimize the likelihood of this kind of event. Our code used static libraries, and I think O / S also used the C static library (that was a long time ago!). Using shared libraries is changing the dynamics.

Apocryphal information with a lot of blurry details is omitted - this is the thing that, as a rule, is a temporary problem, because people correct them pretty quickly.

+3
source

Source: https://habr.com/ru/post/1268811/


All Articles