Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find resources about "modern" C programming? [closed]

Tags:

c

In spite of having read K&R, and having even taught C classes, I find myself embarrassingly unable to fully understand what one might call "modern" C.

There seems to be many unwritten conventions in modern programming that, as far as I know, aren't documented anywhere.

Take, for example, the SQLite source code. In it I find for instance:

 SQLITE_API int sqlite3_close(sqlite3 *);

What does SQLITE_API stand for? How is this even syntactically correct?

Or this:

#ifndef _SQLITE3_H_
#define _SQLITE3_H_

Is there an accepted convention somewhere on when to prefix macros with underscores? Sometimes I see macros prefixed with two underscores.

Or what about the use of fixed-size types, such as uint32 and so forth. When should one use this practice, and when not? What about the new-ish bool type, when should it be preferred over simple ints?

These are some of the questions I pose myself when I read other people's source code. Is there a reference somewhere that might help me answer these questions?

like image 300
lindelof Avatar asked Jun 10 '11 14:06

lindelof


People also ask

Where can I get help for C programming?

At FavTutor, we have expert tutors in C programming who help you accomplish impeccable quality assignments well within the required deadline. Moreover, you can also connect with our tutors 24/7 through chat or email.

Is C programming still used in 2022?

C might be old, but it is definitely relevant in 2022 and will likely remain so. The simplicity of C provides you with a perfect gateway into the programming world. It helps you understand the detailed implementation of any algorithm.

Do people still write programs in C?

The C programming language has been alive and kicking since 1972, and it still reigns as one of the fundamental building blocks of our software-studded world.


2 Answers

SQLITE_API in code like this is very likely a preprocessor define, that worries about exposing the call in e.g. a DLL library build. That's pretty common.

If it's all upper case in C, chances are it's a preprocessor symbol, and a good idea is often to run the game through the preprocessor and read what comes out.

like image 175
unwind Avatar answered Nov 11 '22 20:11

unwind


Afaik GNU coding standards are under constant revision/update so might be a good snapshot of 'modern' style.

http://www.gnu.org/prep/standards/

Re: specifically single or double undercores, in my experience and from what I often read; it's grossly accepted safer to avoid double underscore prefixes as these are usually 'reserved' for framework/system/compiler-specific and compiler-related elements, thus macros intended soley for use within the module/package/unit/project they are defined should avoid being undescore-prefixed at all.

Most institions have their own language coding standards and guidelines which can vary quite significantly. As ever, consistency is key.

like image 43
daz azemoon Avatar answered Nov 11 '22 18:11

daz azemoon