By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

pointer problem

P: 37
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(input);
My question is how do i get the array_length value, being in my_function()?
Thanks
Aug 14 '07 #1
Share this Question
Share on Google+
4 Replies


P: 84
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(input);
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.
Aug 14 '07 #2

P: 16
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(input);
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.

Expand|Select|Wrap|Line Numbers
  1. void my_function(BYTE* input, unsigned int len)
  2. {
  3. // do something
  4. }
  5.  
  6.  
If this is C++ I recommend using a STL container like vector instead of an array.
Aug 14 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
TripleDES has the correct solution.

Do not use a global variable.
Aug 14 '07 #4

P: 37
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
Aug 14 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.