为什么我不能将数组值返回给主函数?
why can't i return array values to main function?
我在 Linux 中创建了一个用于创建线程的主函数,其中包含读取该数据的函数。 我的主代码包含线程初始化为:
主要功能:
int main(int argc , /*no of aruments*/
char *argv[])/*store each argument values*/
{
pthread_t thid[count];
create_thread(argv,count,&thid);
}
和我的函数为:
int create_thread(char *argv[],int count , pthread_t **thid)
{
for(index = 1; index <= count; index++)
{
status = pthread_create(&thid[index],NULL,file_op,(void*) mystruct);/*create main threads*/
}
}
我收到错误,例如
function.c:: warning: passing argument 1 of ‘pthread_create’ from incompatible pointer type
/usr/include/pthread.h: note: expected ‘pthread_t * __restrict__’ but argument is of type ‘pthread_t **
和
main.c: In function ‘main’:
main.c:: warning: passing argument 3 of ‘create_thread’ from incompatible pointer type
function.c:: note: expected ‘pthread_t **’ but argument is of type ‘pthread_t (*)[(long unsigned int)(count)]’
线程代码有问题吗? 我如何声明正确的语法?我想获取从函数到主数组的所有值。
进行两项更改:
create_thread(argv,count,thid);
和
int create_thread(char *argv[],int count , pthread_t *thid)
这会将数组传递给您的函数,并将传递一个指针,指向要由 pthread_create 更新的线程 ID 之一。
pthread_create函数的第一个参数需要pthread_t *
。您传递了错误类型的参数。
看看这个: pthread_create
此外,create_thread()
正在写入 thid
数组的末尾。循环应该是
for (index = 0; index < count; index++)
相关文章:
- 从函数返回const char*数组
- 检查函数返回类型是否与STL容器类型值相同
- 从 c 或 cpp 系列子函数返回到主函数
- 从函数返回任意简单类型的数据
- 警告:在函数返回类型 [-Wignore 限定符] 时忽略类型限定符
- 从 C++ 中的函数返回数组地址问题
- VirtDisk.h QueryChangesVirtualDisk() 函数返回 RangeCount 为 0
- 为什么glGetSubroutineIndex为不同的函数返回相同的值?
- 在 c++ 中将函数返回类型指定为模板参数
- 从封装在对象中的函数 C++ 返回时为空的列表
- 为什么向量内部的指针在从函数返回时会发生变化?
- 函数返回的 rvalue 引用(表达式)是 xvalue - 但没有标识?
- 程序中的布尔函数返回输入的范围无论如何都是无效的
- 寿命延长从函数返回引用
- 程序不向函数返回值
- 字符串函数返回奇怪的值
- 类的大问题,以及从空函数c++返回
- 为什么在尝试测量函数返回所需的时间时,我的运行时编号是错误的?
- C++二叉搜索树模板从函数返回节点
- NVCC 错误:string_view.h:constexpr 函数返回是非常量