LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-11-2012, 01:35 PM   #1
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Rep: Reputation: Disabled
Beginning C - current source of practical info on POSIX, and related, for a beginner?


I'm self-studying C, for fun. I'm 58, and have little previous programming experience. Even though I have no plans to write code professionally, I'd like to learn C properly rather than just enough to write a few things that work only on my own desktop which may not be portable.

I'd like to find a source which discusses the relative importance of various standards as applied to current programming practice. For instance, should I pay attention to ANSI, or POSIX, or both? Other important relevant standards I should learn about? Has POSIX all-but-replaced ANSI? Is POSIX.1-2008 a superset of POSIX.1-2001? Which of the many compiler flags should I use (or not use)? Which functions/macros should I prefer (or avoid) for portability and robustness? Etc.

Can you recommend a current source that discusses the practical use of standards for beginning programmers, particularly for C in the *nix environment?

I have a copy of "POSIX Programmer's Guide", by Donald Lewine, which I find somewhat useful, but it's 20 years old...

Is there an online source that I could easily check/browse?

Thanks,
Keith Ostertag
 
Old 03-11-2012, 10:18 PM   #2
Da_Nuke
LQ Newbie
 
Registered: Aug 2011
Posts: 12

Rep: Reputation: Disabled
POSIX is Linux's programming API, and one of the things it includes is ANSI C, which is the specification of only the C language and its core functions. ANSI, therefore, is a subset of the whole POSIX specification. Some things that you find on POSIX but not on ANSI C, for example, is threads, mutual exclusion semaphores, pipes and message passing.

Now, that said, the GNU C Library that comes bundled with all Linuxen does more than just implementing the ANSI C standard; it goes all the way to implementing the whole POSIX specification as well as the programming part of the Single UNIX Specification. This is why there's also the µClibc, which is a stripped-down GNU C Library for microcontrollers and embedded systems.
 
1 members found this post helpful.
Old 03-12-2012, 08:41 AM   #3
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Original Poster
Rep: Reputation: Disabled
Hi DA_Nuke- Thanks for responding.

You say ANSI is a "subset of the whole POSIX specification", but this weekend (for example) I found that strdup is POSIX.1-2001 conforming but not ANSI- using the -ansi flag for gcc I get an "implicit declaration" warning. The man page says "strdup() conforms to SVr4, 4.3BSD, POSIX.1-2001". So, evidently, strdup is POSIX but not ANSI... at least that is how it appears to me.

I'd like to find a resource which explains this type of detail.

Keith Ostertag

EDIT: It occurs to me after more thought... using the -ansi compiler flag is not such a great idea, as it limits me to the old ansi, which would only be useful for compiling for (much) older machines. This is likely to be true for a lot of the compiler flags- which is why I'd like to find a source for advice on which flags to use for which standard and/or purposes...

Last edited by keithostertag; 03-12-2012 at 07:44 PM.
 
Old 03-13-2012, 02:10 PM   #4
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467
Blog Entries: 60

Rep: Reputation: 51
Quote:
Originally Posted by keithostertag View Post
I'm self-studying C, for fun. I'm 58, and have little previous programming experience. Even though I have no plans to write code professionally, I'd like to learn C properly rather than just enough to write a few things that work only on my own desktop which may not be portable.

I'd like to find a source which discusses the relative importance of various standards as applied to current programming practice. For instance, should I pay attention to ANSI, or POSIX, or both? Other important relevant standards I should learn about? Has POSIX all-but-replaced ANSI? Is POSIX.1-2008 a superset of POSIX.1-2001? Which of the many compiler flags should I use (or not use)? Which functions/macros should I prefer (or avoid) for portability and robustness? Etc.

Can you recommend a current source that discusses the practical use of standards for beginning programmers, particularly for C in the *nix environment?

I have a copy of "POSIX Programmer's Guide", by Donald Lewine, which I find somewhat useful, but it's 20 years old...

Is there an online source that I could easily check/browse?

Thanks,
Keith Ostertag
If you are programming for Gnu/Linux, you can use pretty much anything that is available in the system header files and be quite safe. The only (theoretical) downside is that some of the functions are GNU specific, meaning that they aren't part of any (other) standard, and therefore may not be available on other unixes (e.g., BSD, Solaris) which conform to the standards.

Read the manual page FEATURE_TEST_MACROS(7), which explains the macro system available under Gnu/Linux which you can use if you want to limit yourself to conforming to a more restrictive standard.

So, typically what you would do in such a scenario is, when you are coding, set GCC to restrict itself to some base standard (for example, the C99 standard with the -std=c99 flag) and GCC won't make available functions from other standards. Then you use the macros to enable functions for whatever additional standards you want to include. For example, if you enable X/Open 7 you'll get pretty much all the functions out there except the Gnu specific ones, and maybe a few BSD or SysV functions here and there.

Speaking practically though: keep in mind that, these days, some of the other unixes have implemented the Gnu specific functions and headers anyway. (For example, OpenBSD has provides a getopt.h header and getopt_long() function even though these are Gnu extensions.) They are trying to be compatible with Gnu/Linux because it has become so popular and they want to be able to run all our application source code. So you'll want to ask yourself it is worth the inconveniences to code for a more restrictive standard.
 
1 members found this post helpful.
Old 03-13-2012, 03:39 PM   #5
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Original Poster
Rep: Reputation: Disabled
Thank you, hydraMax - that is very useful info, I appreciate it. I had never before heard of the feature_test_macros and will study the man pages more.

Keith
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting system info across POSIX systems hydraMax Programming 6 01-01-2012 03:43 PM
Related to pthreads and timers in POSIX standard geek89 Programming 2 02-18-2010 03:57 AM
Using AD on Windows 2008 Server to hold posix and netgroup info kenneho Linux - Server 2 10-15-2009 02:04 AM
just sharing practical info about installing slackware for beginners Landrew1 Linux - Newbie 1 08-02-2009 07:45 AM
Posix signals with info warrenpatrick Programming 2 11-24-2004 12:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration