3 Replies - 699 Views - Last Post: 21 February 2014 - 01:47 PM Rate Topic: -----

#1 odougs  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 13
  • Joined: 05-January 14

Advice on C Standards, Libraries, and Idiosyncracies

Posted 19 February 2014 - 11:14 PM

Hello,

This question isn't about any code in particular, but rather about (career) goals and practices as a C programmer. I am quite interested in pursuing a career in either embedded development or other low-level software (drivers, etc), and to that end I want to be sure I have a proper foundation in reading/writing (semi)portable, standards-conforming C code.

However, I have some deeply engrained C99 habits, I'm in the process of writing my own libraries for the basic things like List and String and Scanner that make Java so much easier, and I am even starting to consider preprocessor support for things like "object oriented C" (heresy!). So, I fear I may be going too far... I need practice and practical experience, and I need to write some programs to make my life easier, so I want to make writing C easier... but I also want to make sure I'm actually learning C and not a crappy imitation of C++ v0.01!


What is a good balance, given that I want to have the right habits to fit in with existing code / development teams? Should I always be writing C89 and restricting myself to Stdlib as much as possible (plus modest usage of OS APIs)? Or has the professional world moved on and embraced C99, even C11?

Is This A Good Question/Topic? 0
  • +

Replies To: Advice on C Standards, Libraries, and Idiosyncracies

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 6010
  • View blog
  • Posts: 20,661
  • Joined: 05-May 12

Re: Advice on C Standards, Libraries, and Idiosyncracies

Posted 20 February 2014 - 12:01 AM

Who said that low-level code has to be written in C? Many Windows device drivers are actually written in C++.
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is online

  • member icon

Reputation: 5388
  • View blog
  • Posts: 16,809
  • Joined: 25-December 09

Re: Advice on C Standards, Libraries, and Idiosyncracies

Posted 20 February 2014 - 07:26 AM

In the Windows world C90 is probably still king since Microsoft refuses to officially support any of the newer standards. I would say the embedded world is probably similar. So you may need to consider two versions of the same "libraries" one that sticks to C90 and another that actually comes into this century and supports the current standards. However, for drivers and embedded work I recommend you always stay away of things like VLA and the other optional C11 features.

As far as the use of the OS API if you're writing a device driver there is no reason not to use the API, after all a device driver by nature is not portable as a whole. But if you're going to try to write the driver for multiple operating systems make sure you try to separate these API calls into their own functions and files to make migration simpler. If every source file requires something from the OS API then you'll have an operating system specific driver. To me this also means using a variable naming convention that is OS neutral, ie. don't use things like DWORD, LCPTR, and the like which I consider Windows specific, unless you're writing Windows specific drivers.


Jim
Was This Post Helpful? 0
  • +
  • -

#4 odougs  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 13
  • Joined: 05-January 14

Re: Advice on C Standards, Libraries, and Idiosyncracies

Posted 21 February 2014 - 01:47 PM

View PostSkydiver, on 20 February 2014 - 12:01 AM, said:

Who said that low-level code has to be written in C? Many Windows device drivers are actually written in C++.


Good point! I chose C and Linux as the first platforms / tools to become competent in, and I'm glad I did - but since my question is about longer-term goals, it would be good to think outside of that box! Nevertheless, I have heard that C++ is less popular than C, and loosing popularity, for low-level development. Do you think that's true? I'd love to hear of more counter-examples (notable projects & organizations that choose C++ as tool #1).



View Postjimblumberg, on 20 February 2014 - 07:26 AM, said:

In the Windows world C90 is probably still king since Microsoft refuses to officially support any of the newer standards. I would say the embedded world is probably similar. So you may need to consider two versions of the same "libraries" one that sticks to C90 and another that actually comes into this century and supports the current standards. However, for drivers and embedded work I recommend you always stay away of things like VLA and the other optional C11 features.

As far as the use of the OS API if you're writing a device driver there is no reason not to use the API, after all a device driver by nature is not portable as a whole. But if you're going to try to write the driver for multiple operating systems make sure you try to separate these API calls into their own functions and files to make migration simpler. If every source file requires something from the OS API then you'll have an operating system specific driver. To me this also means using a variable naming convention that is OS neutral, ie. don't use things like DWORD, LCPTR, and the like which I consider Windows specific, unless you're writing Windows specific drivers.


Jim



Good to know! I will need to study up on the different language standards a bit more, then, and make sure I can move between them comfortably. What you say about using the OS API seems very sensible, especially about putting platform-specific calls in a specific module.

What would you recommend doing about 3rd party libraries though, including ones written by myself? I'd rather avoid them, but it seems crazy to write a new linked-list implementation in every program that needs one! I know I can't depend upon any specific non-standard libraries in a job interview, but I wonder if using such things will help me grow more quickly as a programmer... or will it be a hindrance to learning 'real' C?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1