uint8_t和unsigned char之间的混淆

问题描述

我正在尝试使用以下命令从头文件调用void process (uint8_t* I1,uint8_t* I2,float* D1,float* D2,const int32_t* dims);

    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);

但是当我在Linux上使用g ++进行编译时,收到消息undefined reference to process(unsigned char*,unsigned char*,float*,int const*) 为什么会这样?

解决方法

,我得到消息未定义引用到进程(unsigned char *,unsigned char *,float *,float *,int const *)为什么会发生?

发生这种情况是因为链接器无法找到功能process(...)定义。如果此函数来自库,则意味着您未链接到包含此函数定义的库。

此外,uint8_t只是gcc中unsigned char的别名。

此外,如果您使用std::vector格式的非常简单和安全的解决方案,则不应该手动管理内存。没有任何malloc的代码:

    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);
,

uint8_t和无符号字符之间的混淆...为什么会发生这种情况?

仅因为uint8_t是系统上unsigned char的类型别名。这两个是同一类型。这是正常的。

未定义的过程引用...为什么会发生?

似乎您未能定义要调用的函数。


P.S。避免在C ++中使用malloc。也要避免拥有裸露的指针。您的示例程序会泄漏内存。

还有什么更好的选择? (我是C ++的新手)

使用std::vector

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...