Versions Compared

Key

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

...

In this non-compliant code example, the string literal "localhost" and integer constant 1234 are embedded directly in program logic, and are consequently difficult to change.

Code Block
bgColor#ffcccc
ifLDAP ( (*ld = ldap_init("localhost", 1234));
if ( ld == NULL) {
  perror("ldap_init");
  return(1);
}

...

Code Block
bgColor#ccccff
#ifndef PORTNUMBER     /* might be passed on compile line */
#  define PORTNUMBER 1234
#endif

#ifndef HOSTNAME        /* might be passed on compile line */
#  define HOSTNAME "localhost"
#endif

/* ... */

ifLDAP ( (*ld = ldap_init(HOSTNAME"localhost", PORTNUMBER ))1234);
if ( ld == NULL) {
  perror("ldap_init");
  return(1);
}

...