What are the most common naming conventions in C?

前端 未结 11 2372
走了就别回头了
走了就别回头了 2020-12-02 04:13

What are the naming conventions commonly use in C? I know there are at least two:

  1. GNU / linux / K&R with lower_case_functions
  2. ? name ? with UpperC
11条回答
  •  再見小時候
    2020-12-02 04:21

    The most important thing here is consistency. That said, I follow the GTK+ coding convention, which can be summarized as follows:

    1. All macros and constants in caps: MAX_BUFFER_SIZE, TRACKING_ID_PREFIX.
    2. Struct names and typedef's in camelcase: GtkWidget, TrackingOrder.
    3. Functions that operate on structs: classic C style: gtk_widget_show(), tracking_order_process().
    4. Pointers: nothing fancy here: GtkWidget *foo, TrackingOrder *bar.
    5. Global variables: just don't use global variables. They are evil.
    6. Functions that are there, but shouldn't be called directly, or have obscure uses, or whatever: one or more underscores at the beginning: _refrobnicate_data_tables(), _destroy_cache().

提交回复
热议问题