Zeyad Khattab
Zeyad Khattab

Reputation: 121

Confusion between uint8_t and unsigned char

I am trying to call void process (uint8_t* I1,uint8_t* I2,float* D1,float* D2,const int32_t* dims); from a header file, using the following

    int n=10;
    size_t size=n*n*sizeof(uint8_t);
    uint8_t* I1 = (uint8_t*)malloc(size);
    uint8_t* I2 = (uint8_t*)malloc(size);
    size=n*n*sizeof(float);
    float* D1=(float*)malloc(size);
    float* D2=(float*)malloc(size);
    const int32_t dims[3] = {n,n,n};
    process(I1,I2,D1,D2,dims);

but when I compile, using g++ on linux, I get the message undefined reference to process(unsigned char*, unsigned char*, float*, float*, int const*) Why does this happen?

Upvotes: 1

Views: 1514

Answers (2)

Waqar
Waqar

Reputation: 9331

, I get the message undefined reference to process(unsigned char*, unsigned char*, float*, float*, int const*) Why does this happen?

It happens because the linker was not able to find the definition for the function process(...). If this function comes from a library, this means that you are not linking to the library which contains the definition for this function.

Also, uint8_t is just an alias for unsigned char in gcc.

Moreover, you shouldn't manually manage the memory when you have a very simple and safe solution in the form of std::vector. Code without any mallocs:

    size_t size = n * n;
    std::vector <uint8_t> I1 (size);
    std::vector <uint8_t> I2 (size);

    std::vector <float> D1(size);
    std::vector <float> D2(size);

    const int32_t dims[3] = {n,n,n};

    process(&I1[0], &I2[0], &D1[0], &D2[0], dims);

Upvotes: 2

eerorika
eerorika

Reputation: 238321

Confusion between uint8_t and unsigned char ... Why does this happen?

Simply because uint8_t is a type alias of unsigned char on your system. These two are the same type. This is normal.

undefined reference to process ... Why does this happen?

It appears that you've failed to define the function that you call.


P.S. Avoid malloc in C++. Also avoid owning bare pointers. Your example program leaks memory.

what's a better alternative ? (I am new to c++)

Use std::vector.

Upvotes: 0

Related Questions