Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Macros vs Inlines

Name: Anonymous 2011-10-15 4:05

Why do so many C programmers define stuff like min and max as macros?

I see stuff like #define MIN(a, b) (a < b ? a : b) everywhere, but then you get issues if you do stuff like MIN(a++, b--). If MIN was an inline function you wouldn't get undefined behavior like that.

Is it because C doesn't have overloadable functions, so you can't define a single MIN that works with every type of number?

Name: Anonymous 2011-10-15 9:12

>>18
[code]/* Standard IO library header inclusion for:
   - fprintf */
#include <stdio.h>

/* Main function.
   It prints the string "Hello, world!".
   It returns an int exit value to the OS.
   It takes the standard parameters
   describing the command-line program
   arguments. */
int
main(argc, argv)
/* Type declarations */
  int argc;
  char* argv[];
{
  /* The string to be printed */
  static
  const char*
  const str =
    "Hello, world!";

  /* Prints the string str to the
     standard output */
  fprintf(stdout,
          "%s\n",
          str);

  /* Returns a successful exit value */
  return 0; 
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List