bug-readline
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why does stdio.h have to be included before readline/readline.h (install


From: Peng Yu
Subject: Why does stdio.h have to be included before readline/readline.h (installed via homebrew) on macOS?
Date: Wed, 19 May 2021 08:28:10 -0500

Hi,

stdio.h must be included before readline/readline.h in the following
program in order for it to compile on macOS. But the program can be
compiled on Linux when stdio.h is deleted.

Why is it so? Is it better to make it behave the same on Linux and
macOS? Thanks.

$ clang -Wall -I/usr/local/opt/readline/include
-L/usr/local/opt/readline/lib main.c -lreadline

#ifdef __APPLE__
#include <stdio.h>
#endif
#include <readline/readline.h>
#include <readline/history.h>
#include <stdlib.h>

int main(int argc, char **argv) {
  while(1) {
    char *line = readline("> ");
    if(line == NULL) {
      break;
    } else if(strcmp(line, "q") == 0) {
      free(line);
      break;
    }

    if(strcmp(line, "") != 0) {
      printf("%s\n", line);
      add_history(line);
    }
    free(line);
  }
  return 0;
}

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]