This shows you the differences between two versions of the page.
— |
extdef.h [2017/12/06 11:18] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== extdef.h ====== | ||
+ | < | ||
+ | /** | ||
+ | * extdef.h - A header of macros to augment the C standard headers. | ||
+ | * | ||
+ | * v1.0 - 10/06/2012 - Initial release | ||
+ | | ||
+ | * Copyright (C) 2012 - Joel Holdsworth | ||
+ | * | ||
+ | * Redistribution and use in source and binary forms, with or without | ||
+ | * modification, | ||
+ | * are met: | ||
+ | * | ||
+ | * 1. Redistributions of source code must retain the above copyright | ||
+ | | ||
+ | * 2. Redistributions in binary form must reproduce the above copyright | ||
+ | | ||
+ | | ||
+ | * | ||
+ | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | ||
+ | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
+ | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
+ | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
+ | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
+ | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
+ | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
+ | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
+ | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
+ | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
+ | **/ | ||
+ | |||
+ | #ifndef _EXTDEF_H | ||
+ | #define _EXTDEF_H | ||
+ | |||
+ | #define countof(x) (sizeof(x)/ | ||
+ | |||
+ | #define begin_element(x) (&x[0]) | ||
+ | #define end_element(x) (& | ||
+ | |||
+ | #endif /* _EXTDEF_H */ | ||
+ | </ | ||
+ | |||
+ | ===== Overview ===== | ||
+ | extdef.h is a companion header to add extra macros to augment the C/C++ standard set. The header is released under the BSD license. | ||
+ | ===== Reference ===== | ||
+ | ==== countof() ==== | ||
+ | This macro is a a companion to the '' | ||
+ | ==== begin_element() & end_element() ==== | ||
+ | '' | ||
+ | |||
+ | These two macros are provided so that C style array can neatly integrate with [[http:// | ||
+ | |||
+ | === Example === | ||
+ | Finding the maximum value in an array. | ||
+ | < | ||
+ | const int a[] = {1, 3, 2, 5, 4}; | ||
+ | const int max = max_element(begin_element(a), | ||
+ | </ | ||