www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How does one reset the pointer to the begining of _argptr

reply Tyro <ridimz_at yahoo.dot.com> writes:
I have the following:

void foo(...)
{
   void* argptr = _argptr;
   foreach(TypeInfo ti; _arguments)
   {  if(ti == typeid(char[]))
      { /* do something */
        argptr += (char[]).sizeof;}
      else if(ti == typeid(sometype))
      { /* do something else */
        argptr += (sometype).sizeof;}
   }
   /+
   At this point the pointer should be pointing
   just beyond the last argument. My question
   question is how do I get it back to where it
   was when I initially entered this function?

   I have tried decrementing the pointer with:
      foreach(TypeInfo ti; _arguments)
        if(ti == typeid(sometype))
          argptr -= sometype.sizeof;
   but that doesn't help at all.
   +/
}

thanks for your assistance.
Andrew
Dec 21 2004
parent reply "Simon Buchan" <currently no.where> writes:
On Tue, 21 Dec 2004 06:24:54 -0500, Tyro <ridimz_at yahoo.dot.com> wrote:

 I have the following:

 void foo(...)
 {
    void* argptr = _argptr;
    foreach(TypeInfo ti; _arguments)
    {  if(ti == typeid(char[]))
       { /* do something */
         argptr += (char[]).sizeof;}
       else if(ti == typeid(sometype))
       { /* do something else */
         argptr += (sometype).sizeof;}
    }
    /+
    At this point the pointer should be pointing
    just beyond the last argument. My question
    question is how do I get it back to where it
    was when I initially entered this function?

    I have tried decrementing the pointer with:
       foreach(TypeInfo ti; _arguments)
         if(ti == typeid(sometype))
           argptr -= sometype.sizeof;
    but that doesn't help at all.
    +/
 }

 thanks for your assistance.
 Andrew

whats wrong with argptr = _argptr again? -- "Unhappy Microsoft customers have a funny way of becoming Linux, Salesforce.com and Oracle customers." - www.microsoft-watch.com: "The Year in Review: Microsoft Opens Up" -- "I plan on at least one critical patch every month, and I haven't been disappointed." - Adam Hansen, manager of security at Sonnenschein Nath & Rosenthal LLP (Quote from http://www.eweek.com/article2/0,1759,1736104,00.asp) -- "It's been a challenge to "reteach or retrain" Web users to pay for content, said Pizey" -Wired website: "The Incredible Shrinking Comic"
Dec 21 2004
parent reply Tyro <ridimz_at yahoo.dot.com> writes:
Simon Buchan wrote:
 On Tue, 21 Dec 2004 06:24:54 -0500, Tyro <ridimz_at yahoo.dot.com> wrote:
 
 I have the following:

 void foo(...)
 {
    void* argptr = _argptr;
    foreach(TypeInfo ti; _arguments)
    {  if(ti == typeid(char[]))
       { /* do something */
         argptr += (char[]).sizeof;}
       else if(ti == typeid(sometype))
       { /* do something else */
         argptr += (sometype).sizeof;}
    }
    /+
    At this point the pointer should be pointing
    just beyond the last argument. My question
    question is how do I get it back to where it
    was when I initially entered this function?

    I have tried decrementing the pointer with:
       foreach(TypeInfo ti; _arguments)
         if(ti == typeid(sometype))
           argptr -= sometype.sizeof;
    but that doesn't help at all.
    +/
 }

 thanks for your assistance.
 Andrew

whats wrong with argptr = _argptr again?

With every incrementation, I have modified argptr. Therefore, simply assigning it the values of _argptr will destroy the new values I've just assigned it. I want to get back to the beginning of argptr which now contains the new values I inserted.
Dec 21 2004
next sibling parent "Simon Buchan" <currently no.where> writes:
On Tue, 21 Dec 2004 06:46:04 -0500, Tyro <ridimz_at yahoo.dot.com> wrote:

 Simon Buchan wrote:
 On Tue, 21 Dec 2004 06:24:54 -0500, Tyro <ridimz_at yahoo.dot.com>  
 wrote:


   whats wrong with argptr = _argptr again?

With every incrementation, I have modified argptr. Therefore, simply assigning it the values of _argptr will destroy the new values I've just assigned it. I want to get back to the beginning of argptr which now contains the new values I inserted.

Hmm, I don't get it... how can you assign values to a void*, then want to move it back to the start? The ONLY information a void* holds is its location, by definition. Is what you want to create a new void* with the values of the args memcpy'ed after it? -- "Unhappy Microsoft customers have a funny way of becoming Linux, Salesforce.com and Oracle customers." - www.microsoft-watch.com: "The Year in Review: Microsoft Opens Up" -- "I plan on at least one critical patch every month, and I haven't been disappointed." - Adam Hansen, manager of security at Sonnenschein Nath & Rosenthal LLP (Quote from http://www.eweek.com/article2/0,1759,1736104,00.asp) -- "It's been a challenge to "reteach or retrain" Web users to pay for content, said Pizey" -Wired website: "The Incredible Shrinking Comic"
Dec 21 2004
prev sibling parent Georg Wrede <Georg_member pathlink.com> writes:
In article <cq92dt$2noi$1 digitaldaemon.com>, Tyro says...
Simon Buchan wrote:
 On Tue, 21 Dec 2004 06:24:54 -0500, Tyro <ridimz_at yahoo.dot.com> wrote:
 
 I have the following:

 void foo(...)
 {
    void* argptr = _argptr;
    foreach(TypeInfo ti; _arguments)
    {  if(ti == typeid(char[]))
       { /* do something */
         argptr += (char[]).sizeof;}
       else if(ti == typeid(sometype))
       { /* do something else */
         argptr += (sometype).sizeof;}
    }
    /+
    At this point the pointer should be pointing
    just beyond the last argument. My question
    question is how do I get it back to where it
    was when I initially entered this function?

    I have tried decrementing the pointer with:
       foreach(TypeInfo ti; _arguments)
         if(ti == typeid(sometype))
           argptr -= sometype.sizeof;
    but that doesn't help at all.
    +/
 }

 thanks for your assistance.
 Andrew

whats wrong with argptr = _argptr again?

With every incrementation, I have modified argptr. Therefore, simply assigning it the values of _argptr will destroy the new values I've just assigned it. I want to get back to the beginning of argptr which now contains the new values I inserted.

This really looks like using a wrench where a hammer should be used. (Or the other way 'round.) Instead of answering your question, maybe we should try to find out _what_ and _why_ you are trying to do? For example, if you want to change the strings, why don't you copy them into another array?
Dec 22 2004