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


Groups > comp.lang.c++ > #10862

Re: a kind of template (or macro) to reuse parts of code...

From Richard Damon <news.x.richarddamon@xoxy.net>
Newsgroups comp.lang.c++
Subject Re: a kind of template (or macro) to reuse parts of code...
Date 2011-10-15 12:02 -0400
Organization A noiseless patient Spider
Message-ID <j7caq9$311$1@dont-email.me> (permalink)
References <j7a2dr$reb$1@gregory.bnet.hr> <j7a9o8$g7k$1@dont-email.me> <j7c4ds$hu3$1@gregory.bnet.hr> <j7cacb$sr9$1@gregory.bnet.hr>

Show all headers | View raw


On 10/15/11 11:54 AM, A wrote:
> I tried this (as an dumb example) and it seems to work...
> I think I'll be learning a bit more about macros.
>
> The only drawback I see so far is the fact I can't debug the CODEPART1 and
> CODEPART2 but except that it is working as intented.
>
> #define CODEPART1                         \
> std::vector<int>  abc(5);                  \
> for (int i = 0; i<  abc.size(); i++)      \
> {                                         \
> abc[i] = i;                               \
> }
>
> #define CODEPART2                         \
> return abc[4];
>
> int overload(int a)
> {
> CODEPART1
> abc[0] = 0;
> CODEPART2
> }
>
> int overload(__int64 a)
> {
> CODEPART1
> abc[1] = 0;
> CODEPART2
> }
>
>

The limitations on debugging are a function of the debugger. A good 
debugger will at least let you switch into an assembly view of the code 
to see what is happening.

If you are having trouble with a macro expansion, replacing the macro 
with its expanded text temporarily normally will make it easier to debug 
(and then if you needed to change the code, go back and fix the original 
macro to match, but ideally you would have debugged the snippet as 
independent code before pushing it into a macro.

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


Thread

a kind of template (or macro) to reuse parts of code... "A" <a@a.a> - 2011-10-14 21:25 +0200
  Re: a kind of template (or macro) to reuse parts of code... "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2011-10-14 22:08 +0200
    Re: a kind of template (or macro) to reuse parts of code... "A" <a@a.a> - 2011-10-14 22:16 +0200
      Re: a kind of template (or macro) to reuse parts of code... Ian Collins <ian-news@hotmail.com> - 2011-10-15 09:22 +1300
        Re: a kind of template (or macro) to reuse parts of code... "A" <a@a.a> - 2011-10-14 22:36 +0200
          Re: a kind of template (or macro) to reuse parts of code... Ian Collins <ian-news@hotmail.com> - 2011-10-15 09:53 +1300
            Re: a kind of template (or macro) to reuse parts of code... "A" <a@a.a> - 2011-10-15 16:22 +0200
              Re: a kind of template (or macro) to reuse parts of code... Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-10-15 16:54 +0000
          Re: a kind of template (or macro) to reuse parts of code... Noah Roberts <roberts.noah@gmail.com> - 2011-10-14 14:07 -0700
      Re: a kind of template (or macro) to reuse parts of code... Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-10-15 07:33 +0000
    Re: a kind of template (or macro) to reuse parts of code... "A" <a@a.a> - 2011-10-14 22:18 +0200
  Re: a kind of template (or macro) to reuse parts of code... Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-10-14 23:01 +0200
  Re: a kind of template (or macro) to reuse parts of code... Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-14 17:31 -0400
    Re: a kind of template (or macro) to reuse parts of code... "A" <a@a.a> - 2011-10-15 16:13 +0200
      Re: a kind of template (or macro) to reuse parts of code... "A" <a@a.a> - 2011-10-15 17:54 +0200
        Re: a kind of template (or macro) to reuse parts of code... Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-15 12:02 -0400

csiph-web