pointer problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dreea
    New Member
    • Aug 2007
    • 37

    pointer problem

    Hello all! Can you help me with the following issue?
    I have a pointer BYTE *input and i initialize it like that:
    input=new BYTE[array_length] and then i pass the variable "input" as a parameter to a function my_function(inp ut);
    My question is how do i get the array_length value, being in my_function()?
    Thanks
  • sanctus
    New Member
    • Mar 2007
    • 84

    #2
    Originally posted by Dreea
    Hello all! Can you help me with the following issue?
    I have a pointer BYTE *input and i initialize it like that:
    input=new BYTE[array_length] and then i pass the variable "input" as a parameter to a function my_function(inp ut);
    My question is how do i get the array_length value, being in my_function()?
    Thanks
    The easiest way I see (and maybe as well the less professional) is just to make the variable array_length global and then you can access it everywhere.

    Comment

    • TripleDES
      New Member
      • Aug 2007
      • 16

      #3
      Originally posted by Dreea
      Hello all! Can you help me with the following issue?
      I have a pointer BYTE *input and i initialize it like that:
      input=new BYTE[array_length] and then i pass the variable "input" as a parameter to a function my_function(inp ut);
      My question is how do i get the array_length value, being in my_function()?
      Thanks
      You can just pass the length of the array as the second parameter.

      Code:
      void my_function(BYTE* input, unsigned int len)
      {
      // do something
      }
      If this is C++ I recommend using a STL container like vector instead of an array.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        TripleDES has the correct solution.

        Do not use a global variable.

        Comment

        • Dreea
          New Member
          • Aug 2007
          • 37

          #5
          Thank you for your answers.
          Meanwhile, I solved my problem by passing the length as function parameter.
          I don't think that a global variable is a good idea, the function i call is from a dll linked at run-time

          Comment

          Working...