How to write documentation comments in ANSI C? [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 5 years ago.
Improve this question
I can't find how to write comments in C. I mean I know about // and /* */, what I mean is where can I find good practices? Like if I have a function, how do I write the #param variable is the value bla bla, like it is done in Java?
Are there any standards for this? Or can I just do it like I do it in Java?

There are many different standards, if you want to generate documentation, try doxygen

You can use javadoc standard and then use doxygen that understands javadoc to generate a documentation.
In doxygen I recommend using the option JAVADOC_AUTOBRIEF set to YES. If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the first line (until the first dot) of a Javadoc-style comment as the brief description.
Example for a class definition:
/**
* A brief description. A more elaborate class description
* #param bool somebool a boolean argument.
* #see Test()
* #return The test results
*/
(Some more examples in the doxygen manual)
Installation is really simple, there is a GUI and a nice graphical visualisation available with:
apt-get install doxygen doxygen-gui graphviz
Run the gui calling doxywizard and use the Wizard settings, only JAVADOC_AUTOBRIEF has to be set there in "Expert" settings.

There are no standards follow the standard which your company mandates.
A popular way to create documentation from projects is to use doxygen.

An option is to use the doxygen format of writing comments - this has the added benefit of being able to generate html/latex and other sorts of docs for your code.

Related

How to use regex in C/Where to find the files? [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 1 year ago.
Improve this question
I want to use regex and I saw that the POSIX regular expression library provides functions but how do I include the library? Where to find the files? I googled a lot and did not find any manual.
Can anyone help me by providing a manual or a link to a manual? I am using Visual Studio Code
C by itself doesn't have regex, but there are multiple libraries providing this functionality, like:
PCRE and PCRE2 - http://www.pcre.org/
libgnurx - https://github.com/TimothyGu/libgnurx
TRE - http://laurikari.net/tre/about/
sregex - https://github.com/openresty/sregex
slre - https://github.com/cesanta/slre
liblightgrep - https://github.com/strozfriedberg/liblightgrep
RxSpencer - https://github.com/garyhouston/rxspencer
RE2 - https://github.com/google/re2/
Oniguruma - https://github.com/kkos/oniguruma
Onigmo - https://github.com/k-takata/Onigmo
Hyperscan - https://www.hyperscan.io/
And there are probably more regex libraries out there.
I have been able to compile all of the above from source for Windows using MinGW-w64.
Most commonly used are PCRE, PCRE2, libgnurx, but Oniguruma and Hyperscan are interesting alternatives.
If you're using C++ there is also std::regex or boost::regex.

How do you add/specify predefined macros for GCC? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
important thing: -D does not apply here.
Is it possible to declare macros that appear in every compilation (much like predefined macros) in some dynamic manner (meaning I'm lazy to recompile gcc)? or do I have to recompile my gcc? Should I have to recompile, how do I specify my predefined macros?
You might consider providing some (or improving yours) spec file.
You could patch the gcc/c-family/c-cppbuiltin.c file of the source code of GCC.
You could code then use a GCC plugin defining additional predefined macros.
But I am sure it is a very bad idea; I recommend instead passing explicitly some -D flag to your compiler; your question smells badly as some XY problem. You need to motivate your question.
You could instead organize your PATH variable and add appropriately some gcc shell script adding that -DMACRO option and explicitly invoking e.g. /usr/bin/gcc with it.
On Linux you can
use an alias:
alias gcc="gcc -DMACRO1 -DMACRO2"
Copy old /usr/bin/gcc to /usr/bin/gcc.original. Make your own shell script and name it /usr/bin/gcc, inside which you have
exec /usr/bin/gcc.original -DMACRO1 -DMACRO2 "$#"

How to create my own libraries to get started with an OS? [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 6 years ago.
Improve this question
I am learning OS concepts. I created a simple boot loader in ASM and a looping kernel file in C. I compiled them both and it works.
Now I need to print some text using kernel, which is in C. I learnt that while on developing an OS, usage of standard library functions must be omitted. So how can I create my own library. I mean to print a text to screen without including any standard header file. How can I do that? Should I use inline assembly or any other methods?
Making it so simple, my question is, How C language can interact with the hardware without standard libraries?
I do the same 15 years ago :) , you are forced to use your own kernel functions, based in the HAL concept (hardware abstraction layer). You build a HAL based module, as an example, a screen output driver. This driver should be built with two sides: The side who is in contact with your own custom OS, and the side who is in contact with your very specific hardware. So, if at any given moment you change the hardware then your OS is not affected by this change. This is called (formal) : Interface. Is a software pattern concept.
Good look. is a very intersting project :)
As a pseudo code example:
// yourclientprogram.c
include "screendriver.h"
i = new instance of LCDScreenDriver;
i.selectScreen(0);
i.printf("%s","hello");
So, your kernel files will looks like this:
//screendriver.h
class LCDScreenDriver extends ScreenDriver {
protected function output(data){
...very specific ASM code for your LCD monitor goes here..
...this code is very specific to output a -data- buffer
...and nothing more than this
}
}
class ScreenDriver {
protected function output(data); // a virtual pure function
public function printf(args,...){
dataTobePrinted = ..make your own printf methods...
this.output(dataToBePrinted);
}
}

Automatic create function block diagram from ansi c code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Does anyone know a tool that is able to create "function diagrams" from ansi c code?
By "function diagram" I mean a chart that represents an overview of files, functions and their relations. I imagine it to be something like a circut diagram.
Eg. if have the following code:
//MyProgram.c
int main(int argc, char** argv)
{
Foo();
Bar();
return 0;
}
//Slave.h
void Foo();
void Bar();
The chart would be something like the following picture:
Does it have an official name? Dependency diagram, perhaps?
I've looked at bit on Doxygen. But that one clearly states that:
Doxygen has built-in support to generate inheritance diagrams for C++ classes.
Same thing with many UML tools. I don't have any classes. Although my c files may come close.
What you refers is called Call Graph.
There's a list of tools to generate them: http://en.wikipedia.org/wiki/Call_graph#Software
There couple of software which are not free anymore e.g www.scitools.com which has a tool called Understand C. This I'm sure will do what you are looking for, there are other tools like BOUML ( this is free tool). Other than this the list provided by qiao is good reference.
I think I've found the origin of my idea. Displaying code as "components with connected input/output" is a LabVIEW concept. (I'm not a complete nutter for seeking out this kind diagram then ;)
However as far as I know, LabVIEW doesn't do what I want it to. LabVIEW is for building and connecting functionality. Widely used by hw/fw people. (Which are also my target audience.) It will not reverse engineer code into diagrams.
Strange that these diagrams doesn't really exists. It seems to me that people such as embedded programmers, ansi c, low level, hw etc. would love them.

Commenting C code, header and source files [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 5 years ago.
Improve this question
I'm looking for a "best practice" to document my C code. Like in any project I have some header files ".h" and the respective source file ".c"
In the header file what kind of comment you put in? And in source files?
The question arise up because since I commented well my header files, the c files looks like a mess.
What's your best practices in keeping the code well commented?
The header is meant for users of the code. So in there I document the interface: how to use it, preconditions and postconditions, etcetera.
The .c file is for maintainers. In there, I document the implementation: how things work internally, and why they work that way.
I suggest adopting the conventions imposed by a tool like Doxygen. Then instead of just code comments, you can also generate HTML/PDF/Latex etc documentation and its gives you good conventions.
Agree with Thomas about the cpp files
If this is a personal project I'd suggest there are plenty of coding standards out there you could adopt (almost all include sections on how to lay out comments).
If not, I would imagine your company / teaam / project already has something in place so use that.
For source files I suggest you create a comment template for File Header and Function Header.
In case of File Header Comments, you should have a brief description of the file, function names, author, date of creation and history to record modifications.
Incase of function header, you can explain the logic and purpose of the function and various parameters. Please ensure that any complex logic or deviation from common behaviour is well documented through comments.

Resources