1

I have this typedef

typedef unsigned char uint8;

and this variable

public : uint8* bufferOfExchange;

how could I initialize this buffer?

bufferOfExchange = ???
p.campbell
  • 98,673
  • 67
  • 256
  • 322
curiousity
  • 4,703
  • 8
  • 39
  • 59

2 Answers2

2

Like this:

bufferOfExchange = new uint8[bufferSize]; //bufferSize is size_t type. 

//or
bufferOfExchange = otherBuffer; //otherBuffer is of same type

What else do you think?

Better choice would be to use std::vector<uint8> instead of uint8*:

std::vector<uint8> bufferOfExchange;

Now, read some good book to know how to use std::vector.

Nawaz
  • 353,942
  • 115
  • 666
  • 851
1

Well you don't have a buffer, only an uninitialized pointer. You can create a buffer with new like this:

bufferOfExchange = new uint8[10];

(10 is an arbitrary choice - use the buffer size you need.)

For real code however, you would probably want std::vector<uint8>.

Steve Fallows
  • 6,274
  • 5
  • 47
  • 67