Which naming convention should I use for a struct? [closed] - c

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
In plain C, I will name a struct like this:
struct MyStruct
{
int something;
};
But, since I'm now programming under Windows, I want my code to be very consistent in which refers to naming conventions. So, my variables are now named using mixedCase instead of lower_case and my functions are now using CapWords. I have seen some structs with all capital letters, but I don't like this very much because I reserve that for constants and macros.
Thanks.

Check out this link if you want a reference on Naming Conventions in C.
As long as you're consistent with using CamelCase of under_score conventions for whatever purpose, it doesn't really matter.
What are the most common naming conventions in C?

Here is a similar question:
Naming convention for Win32/MFC with C++
MSDN naming guideline locates at http://msdn.microsoft.com/en-us/library/ms229002(v=vs.110).aspx
Struct naming convention is described at http://msdn.microsoft.com/en-us/library/ms229040(v=vs.110).aspx

Related

Why can't we use if or for loop ,while globally in C [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 months ago.
Improve this question
#include <stdio.h>
if(1)
{
}
int main()
{
printf("Hello world");
return 0;
}
if(1) {} is a (selection) statement (6.8.4) and statements are only allowed in function definitions (6.9.1). See Programming Language - C (draft) for the relevant sections, also refer to the informative Annex A.
We could have had a similar mechanism to sh-scripts where it just goes though the file line-by-line, without main. However, having an agreed-upon entry-point allows compilers to abstract compiling from linking for multi-compilation-unit programmes and libraries.
Dennis Ritchie and Ken Thompson developed it after B. This was based on BCPL, developed by Martin Richards. This had a LET START(), much in the way of Fortran, from The FORTRAN Automatic Coding System:
a basic block is a stretch of program which has one entry point and
one exit point
In that way, going from an sh-script to C is entirely possible, but not the other way around.

Making a portable C library interface: extern declaration vs function pointers [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm building a portable C library that needs to interact with a user-defined peripheral.
Here's an example,
My library needs to use a user-defined putc() and a getc().
To my understanding, there's two way to do this cleanly:
Using an "install" function that requires user to define interface with function pointers
// Inside mylib.h
typedef int (*mylib_port_putc)(char c);
typedef int (*mylib_port_getc)(char *c);
void mylib_install_port(mylib_port_putc, mylib_port_getc);
Using the extern keyword to let the user decide where to define the interfaces.
// Inside mylib.h
extern int mylib_port_putc(char c);
extern int mylib_port_getc(char *c);
What's the best way to do this?
I understand that "best" is difficult to define, but your opinion would be greatly appreciated.
EDIT:
I disagree with the StackOverflow maintainers to flag this question as inappropriate. I don't think this website should be limited to "how do I do X?" questions. I understand that asking for opinions will probably not generate a clear answer, but, to me, this is what mentorship looks like.
When you're starting, there's a lot of value in studying knowledgeable people debating tradeoffs.
Sorry for the rent. I know your job is hard. Happy holidays.
I think that the only correct way is the first -
you provide a library initialize(...) function for registering user callback functions - port_putc, port_getc, maybe also callbacks for you library logging, etc.
Such an approach is flexible, and very common.
In the second case, you require the library users to define 2 functions with predefined names in their code.
What happens if he didn't?

Is <windows.h> in collision with "raylib.h" library [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to build a game in C language using raylib library and I wanted to deploy the sleep function that is defined in library. The latter generates a problem in the build of raylib library
Let's say that you have two headers, header1.h and header2.h, both containing a function named foo. Then you can define a new header/source pair:
mynewheader.h:
int header2_foo(int n);
mynewheader.c:
#include <header2.h>
int header2_foo(int n) {
return foo(n);
}
Of course, you can choose any prefix you want, or rename the function completely for that matter. This kind of mimics the namespace feature in C++.
If sleep is the only function you need from Windows.h then use _sleep() from stdlib.h instead. Check this MSDN discussion for further reference.

When will the safe string functions of C11 be part of glibc? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
The C11 standard Annex K defines a bunch of new safer string functions, all suffixed by _s (e.g. strcpy_s).
Do you know when these new functions will become available in the GNU C library glibc?
So far you have to fall back to a third party library like safec.
Do you know when these new functions will become available in the GNU C library glibc?
When someone contributes an implementation and convinces GLIBC maintainers that these functions are good to have.
Relevant thread from 2007.

naming convention for function and structure names and according to ANSI C standard [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I need to know naming convention for function and structure names and according to ANSI C standard.
I read that first letter should start with lower case.
Can I use camel case for naming or should I use underscore between two separate.
ex : print_char or printChar
I need to know what does standard states?
ANSI C standard provides little in the way of conventions only rules.
Function, type and variable identifiers may use any alphanumeric symbol A-Za-z0-9 and underscore _. Names may not begin with a number. This is not a convention but the definition for what a legal name may be.
The only convention I am aware of is the recommendation that names beginning with _ and ending with _t should be avoided. As the standard reserves these for use in the future.

Resources