Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this noncompliant code example, the length of the identifier declaring the function pointer bash_groupname_completion_function() in file bashline.h exceeds by 3 the minimum implementation limit of 31 significant initial characters in an external identifier, introducing the possibility of colliding with the bash_groupname_completion_funcfunct integer variable defined in file b.c, which is exactly 30 31 characters long. On an implementation that exactly meets this limit, the behavior of the program is undefined (see undefined behavior 15). In addition, invoking the function leads to undefined behavior 41 with typically catastrophic effects.

Code Block
bgColor#FFcccc
languagec
/* In bash/bashline.h */
extern char* bash_groupname_completion_function(const char*, int); /* UB 15 */

/* In a.c */
#include <bashline.h>

void f(const char *s, int i) {
  bash_groupname_completion_function(s, i);   /* UB 41 */
}

/* In b.c */
int bash_groupname_completion_funcfunct;   /* UB 15 */

Note: The identifier bash_groupname_completion_function referenced here was taken from GNU Bash version 3.2.

...

In this compliant solution, the length of the identifier declaring the function pointer bash_groupname_completion() in bashline.h is less than 32 characters. Consequently it cannot clash with bash_groupname_completion_funcfunct on any compliant platform.

Code Block
bgColor#ccccff
langc
/* In bash/bashline.h */
extern char* bash_groupname_completion(const char*, int);   

/* In a.c */
#include <bashline.h>

void f(const char *s, int i) {
  bash_groupname_completion(s, i);  
}

/* In b.c */
int bash_groupname_completion_funcfunct; 

Exceptions

DCL40-EX1: No diagnostic need be issued if a declaration that is incompatible with the definition occurs in a translation unit that does not contain any definition or uses of the function or object other than possibly additional declarations. Such code violates MSC12-C. Detect and remove code that has no effect or MSC13-C. Detect and remove unused values, but it does not cause undefined behavior.

...