Category: Embedded C programming

macro functions cover

C: Macro Functions vs Regular Functions vs Inline Functions Part#2

So just to recap what we saw in part 1 of this blog Regular functions are better at Readability and Code size, Macro functions are better at code performance. In this part let’s have a look at inline functions and see how and where to use them and how good of a replacement to a macro function they are. Inline Functions This is the last piece of the puzzle. Inline functions originally came in C++ and later in c99 update, it was added to C programming language so now in C, we have the “inline”  keyword. What are inline functions?...

macro functions cover

C: Macro Function vs Regular Function vs Inline Functions

If you have some experience with C programming and you have had the opportunity to look at some library code then you must have seen something like this The above construct can be called as a macro function or a smart macro. If this code is executed we would get the same result as if ADD is a regular function like in the code listing below. When I was looking at these macro functions I had several questions pop up in my head. Are macros better than normal functions? If so why don’t we use macro functions everywhere? What is...

Are Comments Good or Bad?!

If you look up “Tips to comment code” in google you will find 2 types of answers with 2 different philosophies The first type of answer will say don’t use comments as it makes the entire source code look dirty and cluttered and the right way to write source code is to just make it readable by using good variable names and proper syntax. It is the duty of the reader to be proficient enough to make sense out of it. Only the “traps” in the source code need to be commented out. The second type of answer will say...