Thread: Debuggable C89 templates

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733

    Debuggable C89 templates

    I thought up a way to do proper templates in C89, probably K&C variety too if they support #include, #define, #undef, #error & defined() in some form or way. There's also a loop version that I derived this from (because I initially thought of the loop version then realised the template application after).

    Here's a link to some code that chooses which template to use for emulating an integer, the templates themselves probably have a bug or 2 due to being converted from 1 of my existing implementations but my code became overall smaller and easier to manage for emulating integers so those bugs will be ironed out soon enough.

    include/paw/pawcls.h * e74aef09e57a87462e7911aab4da325294472e4a * Lee Shallis / Dragonbuilder * GitLab

    As for the loop version it can only do 1 scope for now and uses __COUNTER__ to define an index of which to use directly or multiply against another value to get the intended value for that loop, so something like this:

    Code:
    /* loop.h */
    #define BEGAN __COUNTER__
    #define N BEGAN
    #define I (N - BEGAN)
    #include "_loop.h"
    #undef CMP
    #undef INC
    #undef I
    #undef N
    #undef BEGAN
    
    /* _loop.h */
    #if CMP
    #include INC
    #undef N
    #define N __COUNTER__
    #include "_loop.h"
    #endif
    It's a smidge more complicated for error checking but that's the core of it

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Occurred to me a while ago __COUNTER__ is a bad choice for incrementing the value, instead I've switch to __INCLUDE_LEVEL__ for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Templates and Templates objects
    By Dave11 in forum C++ Programming
    Replies: 6
    Last Post: 07-05-2014, 06:27 AM
  2. Help with templates!
    By Cherry65 in forum C++ Programming
    Replies: 7
    Last Post: 12-15-2008, 08:02 PM
  3. Templates
    By axydias in forum C++ Programming
    Replies: 4
    Last Post: 04-30-2006, 01:43 PM
  4. I need help with templates!
    By advocation in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2005, 09:27 PM
  5. using templates
    By Benzakhar in forum Windows Programming
    Replies: 9
    Last Post: 11-24-2003, 06:53 PM

Tags for this Thread