0

I need to access an array outside of this function:

enter code here 
// code in  a .cc file
void 
ldu1::decode_lcw()
{
   uint16_t LCW_BITS[] = 
   {
     410,  411,  412,  413, . . . . . . . . .....
   };
   uint16_t LCW_BITS_SZ = sizeof(LCW_BITS) / sizeof(LCW_BITS[0]);
   uint16_t LCW_BITS = extract(frame_body(), LCW_BITS, LCW_BITS_SZ);
   uint16_t encoded_lcw = LCW_BITS;

   //call the error correction code from another file, lcw_ecc.h 
   //  decoded_lcw is declared protected in 
   //  the .h file corresponding to this .cc file
   lcw_ecc(encoded_lcw, decoded_lcw);
}

the last line there, lcw_ecc() calls this function from an included .h file:

//  code in another file, lcw_ecc.h, which holds the  
//  error correction function definitions
void lcw_ecc(uint16_t encoded_lcw[], uint16_t decoded_lcw[])
{
    uint16_t rs_codewords[144] = {0} ;
    void decode_hamming( uint16_t encoded_lcw[], uint16_t rs_codewords[] );
    void decode_reed_solomon( uint16_t rs_codewords[], uint16_t decoded_lcw[] );
    decode_hamming( encoded_lcw, rs_codewords );
    decode_reed_solomon( rs_codewords, decoded_lcw );
}

The functions work as singletons in terminal, and this code compiles without error in the lib of the program I am working on. However, I have no confidence that it's done right.

My question is, assuming that the code will modify the 'decoded_lcw' as expected, how can I get access to the modified decoded_lcw array in the rest of the .cc file outside of the first function I put up there, the "ldu1::decode_lcw()" ?? if it is declared private or protected will the other member functions declared there be able to access not for modifying it but solely for inspection? could I pass it in as a parameter?

b4hand
  • 9,550
  • 4
  • 44
  • 49
crash
  • 1
  • 1
  • either pass in a pointer to the array to fill or return a vector – IdeaHat Oct 17 '13 at 20:24
  • pass in a pointer to an array?!? – crash Oct 17 '13 at 20:32
  • Well a pointer to the first element of the pre-allocated array. Arrays are pointers. Though I'd probably go with vector. – IdeaHat Oct 17 '13 at 20:34
  • ok right right. so how exactly would i go about passing the pointer to other member functions? – crash Oct 17 '13 at 20:38
  • im sorry if it is a real rookie question but my text book does not deal with this and what i found on the web was cryptic. – crash Oct 17 '13 at 20:39
  • `uint16_t LCW_BITS = extract(frame_body(), LCW_BITS, LCW_BITS_SZ)` and `uint16_t encoded_lcw = LCW_BITS` aren't even legal C. `LCW_BITS` is already an array, you can't assign it by-value as you're doing (but hint: you *can* bury it in a structure and assign *that* back and forth). That said, you should be using a `std::vector` and/or model your functions for iterators, which you can use for *both* arrays and std containers. – WhozCraig Oct 17 '13 at 20:47
  • thanks. ill have to look into that. i am getting some static from the compiler around that bit of code. but back to the original question: can i prototype lcw_ecc() to make it a member function in this .cc file and define it in the other file??? this would make the decoded_lcw available to the whole file right? – crash Oct 18 '13 at 00:42

0 Answers0