0

I'm working on a project for a class regarding shared memory and pipes between child and parent processes and would like to learn more about some issues I'm having so I can fix my code on my own and learn more about the project.

I found code here courtesy of 'WhozCraig' which demonstrates a simple usage of pipes between child and parent processes to send and receive integers.

Were I to save this as, say, 'test.c' and compile it as simple as:

gcc test.c

There are no problems. The code compiles and runs just fine and prints out what it should.

For my project, my code must be compiled with special flags and options. And if I try to compile the code 'WhozCraig' so nicely wrote up, it compiles just fine with a bit of editing (removing the command line arguments which are declared but unused and including a header file for wait() to not be declared implicitly).

However, when I run the code, nothing prints.

Here's how I have to compile my code, and how I compile the example code (which causes the issue of no print outs):

gcc -std=c99 -Wall -Wextra -D_XOPEN_SOURCE=700 -o test test.c -lrt

I would like to know more about the flags we're giving to gcc, to see why both my main program and this example code does not work with it. In particular I'm not sure what the flag D_XOPEN_SOURCE=700 does. I know -Wall and -Wextra print out more warning messages, and -lrt is for ensuring shared memory works well however, just confused about that middle bit, although any extra insight into the other flags will certainly be appreciated if it pertains to my problem.

Community
  • 1
  • 1
  • 1
    `-D_XOPEN_SOURCE=700` is equivalent to `#define _XOPEN_SOURCE 700`. Doesn't look like it should affect WhozCraig's code. `-lrt` is more than "ensuring shared memory works well", however - it means linking with [`librt`](https://stackoverflow.com/a/6754093). – Siguza Oct 22 '16 at 17:40
  • The combination of `-std=c99` and `-D_XOPEN_SOURCE=700` gives you more nearly Standard C and POSIX 2008 than using `-std=gnu99`. It disables some GNU compiler extensions (not all of them; to get more of them suppressed, you need `-pedantic` too). But the `-D_XOPEN_SOURCE=700` makes sure you have POSIX (and X/Open's Single Unix Specification, hence `_XOPEN_SOURCE`) functions and types available — things like shared memory. – Jonathan Leffler Oct 22 '16 at 18:09
  • Thank you all very much for the quick responses, this has helped a lot but hasn't quite helped me fix my code yet. Regardless, thank you both for the clarification! – Alakazam827 Oct 22 '16 at 19:42
  • How are you running the program? If you're just typing `test`, you're running the system utility `test` (which produces no output), not your own code. (This is why you don't call your test programs "test".) – melpomene Oct 22 '16 at 22:29

0 Answers0