Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OSS side C language socket programming

115 views
Skip to first unread message

Shiva

unread,
Mar 20, 2018, 3:48:55 PM3/20/18
to
Hi,

I was trying to execute the OSS manual example for socket programming using C and I encountered a few errors while compiling the code.

It was either about a type (u_short) not being defined or about a function being declared implicitly (gethostid), now I made no modifications to the code from the manual but I'm not aware of the compile options used - I just used the following: c89 -Wnosuppress -g file.c -o out

Now, my compiler listing told me that the parts for defining the type (u_short) or the function declaration - both of which were under two different header files (sys/types.h and netdb.h) - were not loaded into memory/processed because the conditions were not met.

They were either about _TANDEM_ARCH_ or _PUT_MODEL_ & I'm sure I cannot edit the definition of _TANDEM_ARCH_ so is there something else in the compiler options that I should be aware of?

I'm using a J series machine and I got around the issue by manually adding the definition (for u_short) & declaration (for gethostid function) - but I see that a lot more of these definitions and declarations are not added into memory so I'd like to understand what I'm doing wrong.

The program I executed was in the OSS Programmer's guide Page 182 Example 43.

Thanks in advance!

Cheers,
Shiva.

Keith Dick

unread,
Mar 20, 2018, 4:45:28 PM3/20/18
to
That example might have worked at one time (no guarantee), but I would be very surprised if the examples are checked regularly to be sure they continue to work. Unfortunately, you have to expect to have to fix up examples some of the time.

Sometimes the exact wording of a compiler message is critical to understanding its meaning, so rather than paraphrase the messages you get, it is best to reproduce them exactly when you post questions whose answers might depend on the exact meaning of a compiler message.

A few times, I have cured problems similar to what you describe by including -Wextensions among the compiler options. That is one thing I would suggest you try.

I don't understand why you added your own definitions for u_short and gethostid() instead of adding #include for the two header files you mentioned that contain those declarations. Using the header files is also something I would suggest you try right away.

I don't know quite what you mean when you say: "... a lot more of these definitions and declarations are not added into memory ...". On a J-series system, most of the library stuff is included from DLLs, and so will not be included in your runnable object file. So maybe you are over-thinking on that point. On the other hand, if you mean that you get a lot of undefined symbols when you try to run the file, then something is wrong. It might be necessary to name the DLLs that contain the sockets library functions among the compiler options, but I believe that should not be necessary -- most of the DLLs are registered in a directory that the linker knows to consult automatically.

So my suggestion is to try the two things I mentioned above. If that cures the problem, good. If it still don't not work, post again with more details about exactly what you are seeing that indicates a problem.

red floyd

unread,
Mar 20, 2018, 7:57:00 PM3/20/18
to
Try the "cc" command (from the FLOSS package). Alternatively, add the
-D_XOPEN_SOURCE_EXTENDED=1 compiler option.

emailshiva...@gmail.com

unread,
Mar 21, 2018, 1:50:46 AM3/21/18
to
The manual example had the XOPEN_SOURCE_EXTENDED set to 1 so my code had the same thing. So that wasn’t the issue!

emailshiva...@gmail.com

unread,
Mar 21, 2018, 1:59:56 AM3/21/18
to
Keith - Thank you, the -Wextensions directive did the trick! I didn’t add the header file because it was already included but they had conditional defines which were not being loaded because those conditions failed to pass.

The parameters in my initial question were related to those conditions because of which the conditions failed. And there were many of these conditional defines which failed to load as they failed. I understand that I have to provide exact error messages, but I keep working in the financial industry where the work environment is too restricted that you cannot copy any text outside Win6530 but I understand your point - I’ll be more precise next time around!

Thanks for solving the puzzle! May be all those defines are HP extensions and they are not included by default - but the conditions for defines did the exactly give it away so I got stuck. Thanks again. 😊
0 new messages