1

I am very new to C (after many years). I am using lcc64 and have the following statement

char *logMessage = strdup(argv[1]);

I have no idea why I get the error

"operands of = have illegal types 'pointer to char' and 'int"

Any suggestions?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Carmelo
  • 11
  • 1
  • 2
  • 2
    Do you have `#include `? – zch Dec 03 '14 at 22:29
  • 1
    `strdup` is a non-standard extension. You need to have `#include ` *and* you need to ensure that `strdup` is visible. For gcc, you can do the latter by *not* using `-std=cNN`, where `NN` is `90`, `99`, or `11` to specify a version of the C standard. – Keith Thompson Dec 04 '14 at 03:05
  • strdup() dates back to the start of the C language, and all C libraries have it. That makes it as much a standard as anything ratified by an organization. – Andras Dec 04 '14 at 03:22
  • You can also make it visible by putting `#define _POSIX_C_SOURCE 200809L` or `#define _XOPEN_SOURCE 500` before `#include `, if you want to keep a `-std=c99` flag. – Crowman Dec 04 '14 at 03:22

1 Answers1

4

you need to include <string.h> to declare strdup() as returning char*, else the compiler thinks it returns an int

Andras
  • 2,995
  • 11
  • 17