Classic C doesn't use camel-case; I've written code in camel-case in C, and it looks weird (so I don't do it like that any more). That said, it isn't wrong - and consistency is more important than which convention is used.
The general practice for a C style language like Java or JS is to use camelCase for all variables and object members (properties & methods), and PascalCase for class names and constructors. Namespaces (or Packages in Java world) are usually in camelCase. But some languages make an exception to that.
The most important thing here is consistency. That said, I follow the GTK+ coding convention, which can be summarized as follows:
MAX_BUFFER_SIZE
, TRACKING_ID_PREFIX
.GtkWidget
, TrackingOrder
.gtk_widget_show()
, tracking_order_process()
.GtkWidget *foo
, TrackingOrder *bar
._refrobnicate_data_tables()
, _destroy_cache()
."Struct pointers" aren't entities that need a naming convention clause to cover them. They're just struct WhatEver *
. DON'T hide the fact that there is a pointer involved with a clever and "obvious" typedef. It serves no purpose, is longer to type, and destroys the balance between declaration and access.
You know, I like to keep it simple, but clear... So here's what I use, in C:
i,n,c
,etc... (Only one letter. If one letter isn't
clear, then make it a Local Variable)camelCase
g_camelCase
ALL_CAPS
p_
to the prefix. For global variables it would be gp_var
, for local variables p_var
, for const variables p_VAR
. If far pointers are used then use an fp_
instead of p_
.ModulePascalCase
(Module = full module name, or a 2-3 letter abbreviation, but still in PascalCase
.)camelCase
ModulePascalCase
ALL_CAPS
ModulePascalCase
PascalCase
PascalCase
I typedef my structs, but use the same name for both the tag and the typedef. The tag is not meant to be commonly used. Instead it's preferrable to use the typedef. I also forward declare the typedef in the public module header for encapsulation and so that I can use the typedef'd name in the definition.
Full struct
Example:
typdef struct UtilsExampleStruct UtilsExampleStruct;
struct UtilsExampleStruct{
int var;
UtilsExampleStruct *p_link;
};
Well firstly C doesn't have public/private/virtual functions. That's C++ and it has different conventions. In C typically you have:
C++ is more complex. I've seen a real mix here. Camel case for class names or lowercase+underscores (camel case is more common in my experience). Structs are used rarely (and typically because a library requires them, otherwise you'd use classes).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With