Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #143208

Re: Auto-incrementing or auto-decrementing values at compile-time

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c, comp.lang.c++
Subject Re: Auto-incrementing or auto-decrementing values at compile-time
Date 2019-04-19 08:18 +1200
Message-ID <ghs4brFld7fU2@mid.individual.net> (permalink)
References <q9akd2$km7$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


On 19/04/2019 07:51, Rick C. Hodgin wrote:
> I have a need fairly often to return distinct values for a return value.
> I don't particularly care what the values are, but they just need to be
> distinct and unique so that if they are returned later I can identify
> the exact cause of the error, where it failed.
> 
> Something like this:
> 
>       int my_function(void)
>       {
>           if (!test_condition1)
>               return -1;  // Indicate it failed at this test
> 
>           // Arbitrary code
> 
>           if (!test_condition2)
>               return -2;  // Indicate it failed at this test
> 
>           // Arbitrary code
> 
>           if (!test_condition3)
>               return -3;  // Indicate it failed at this test
> 
>           // If we get here, we're good
>       }
> 
> Is there an existing way in C/C++ to automatically create some value
> that would allow me to add a new test and have it inject the new
> value?

An enum.

-- 
Ian.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Auto-incrementing or auto-decrementing values at compile-time "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-18 15:51 -0400
  Re: Auto-incrementing or auto-decrementing values at compile-time scott@slp53.sl.home (Scott Lurndal) - 2019-04-18 20:07 +0000
    Re: Auto-incrementing or auto-decrementing values at compile-time "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-18 16:42 -0400
    Re: Auto-incrementing or auto-decrementing values at compile-time jacobnavia <jacob@jacob.remcomp.fr> - 2019-04-18 23:37 +0200
      Re: Auto-incrementing or auto-decrementing values at compile-time fir <profesor.fir@gmail.com> - 2019-04-18 14:46 -0700
  Re: Auto-incrementing or auto-decrementing values at compile-time Ian Collins <ian-news@hotmail.com> - 2019-04-19 08:18 +1200
  Re: Auto-incrementing or auto-decrementing values at compile-time Bart <bc@freeuk.com> - 2019-04-18 21:25 +0100
  Re: Auto-incrementing or auto-decrementing values at compile-time Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-18 21:37 +0100
    Re: Auto-incrementing or auto-decrementing values at compile-time "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-18 16:45 -0400
      Re: Auto-incrementing or auto-decrementing values at compile-time Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-18 21:59 +0100
  Re: Auto-incrementing or auto-decrementing values at compile-time Richard Damon <Richard@Damon-Family.org> - 2019-04-19 09:13 -0400
    Re: Auto-incrementing or auto-decrementing values at compile-time "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-19 09:25 -0400
      Re: Auto-incrementing or auto-decrementing values at compile-time Richard Damon <Richard@Damon-Family.org> - 2019-04-19 12:37 -0400
        Re: Auto-incrementing or auto-decrementing values at compile-time "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-19 12:52 -0400
  Re: Auto-incrementing or auto-decrementing values at compile-time Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-04-19 17:16 -0600

csiph-web