Email: bknpk@hotmail.com Phone: +972-54-7649119


V

 

This page shows some simple examples for pass a variable to a function by reference. It is implemented as part of a c++ series of exercises , that I did.

  1. The code was taken from an ECC project.
    Example one is a function that counts the number of 1 bits in an unsigned char.

    1. void c_e_ccc_correct::bit_count(const unsigned char& d) {
    2.   unsigned char i, j;
    3.   bit_cnt=0;
    4.   for(i = 0, j=1; i <= 7; i++) {
    5.     if( d & j ) bit_cnt++;
    6.     j *= 2;
    7.   }
    8. }

  2. This example was taken also from the ECC code. This time two classes are passed by reference.

    1. c_e_ccc_correct::c_e_ccc_correct(const c_ecc& prev, const c_ecc& curr) {
    2.   total_bit_cnt=0;
    3.   for(i=0; i <= 2; i++) {
    4.     ecc_c[i]=prev.ecc[i] ^ curr.ecc[i];
    5. #ifdef DGB_1 //{
    6.     cout << "xor " << hex << (unsigned)ecc_c[i] << " " << (unsigned)prev.ecc[i] << " " << (unsigned)curr.ecc[i] << endl;
    7. #endif //}
    8.     bit_count(ecc_c[i]);
    9.     total_bit_cnt += bit_cnt;
    10.   }//for

  ...



Home

some memory VHDL models


A simple c-code program to read a memory array from verilog RTL, using VPI.



Download Area







Search This Site


Feedback This Site




new pages on this site