A collection of commonly used C MACROS
Switch branches/tags
Nothing to show
Clone or download
Latest commit f777e62 Aug 7, 2017
Permalink
Failed to load latest commit information.
.travis.yml Update .travis.yml Aug 7, 2017
CONTRIBUTING.md Create CONTRIBUTING.md Aug 7, 2017
LICENSE Initial commit Aug 1, 2017
Makefile travis test Aug 7, 2017
README.md Update README.md Aug 7, 2017
macros.h Update macros.h Aug 7, 2017
test.c Update test.c Aug 7, 2017

README.md


#macros.h

Useful C #macros
Visit macros »

Open Source Love MIT Licence Build Status Codacy Badge

This is a collection of commonly used C Macros I found on internet, and as suggested by my friends.

Why this is awesome

Using C Macros, we can extend C with a lot of useful functionality. For example, we can create loops like foreach which are very useful and handy when it comes to arrays. These are available in most of high level languages but not in C. But we got macros in C and so we can add on our own!

How to use

Just download macros.h from here and include it to the top.

#include "macros.h"

Note that there is an ASSET macro useful for debugging purpose. To enable it, you need to #define DEBUG before including macros.h.

And these are the macros...

For docs, visit ramdeoshubham.com/macros to learn more about the available macros and their usage.

Contribute

The source is very clear and the macros available are too common you will find them everywhere. A good Macro is : Portable, safe, involves as less arbitrary variables as possible. Although I am trying my best, there might be some exception errors, please correct if you find any. Also, if I missed some other interesting macros, please contribute to make this collection complete and more usable.

Conventions

  1. All macros are in UPPERCASE.
  2. In case of any Boolean Macro, the IS_ prefix should be used. For example, IS_EVEN(x). And they should return a 1 or 0 value.
  3. Macros for loops and conditionals should not end with braces so that the user can have the option for single line as well as block style.
  4. A helper macro, which are expanded by some other main macro, usually they are not intended to be used directly. So they should be mentioned with their expansion level as prefix. For example, PASTE(a,b) expands into PASTE2(a,b) which further expands into a##b.

Credit

The real credits goes to all those great C coders who came up with such creative use of C Macros to extend C. I made this collection in honor of The C language and those unknown programmers. I can only take credit for the efforts I made to collect and bringing it to you.

License

Copyright 2017, Shubham Ramdeo. Code released under the MIT License.

#Handpicked C #Macros with ♥ #love !

Don't forget to STAR if you like it.