访问c中的全局变量



我试图访问一个函数中的全局变量,但我得到不同的结果。

当我运行这段代码时,我的输出是:
5.00000
0.00000

我想要的是访问函数generateData中的全局变量数据,函数是205

这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
// global variable that thread will use
int data_count, thread_count,  bin_count;  
float equalDivisionCount, max_meas, min_meas;
float* data;
int* bin_counts; // final count of element in each bin
float* bin_maxes; // to hold the maximum boundary value of each bin
int* intermediateBinCounts; // hold the data of individial bin in each thread with a offset
void generateData();
struct privateDataInfo {
int starting;
int endingIndex;
int index;
};
void main() {
thread_count = 4;
data_count = 14;
bin_count = 4;
max_meas = 20;
max_meas = 5;
data = (float *)malloc(data_count * sizeof(float));
bin_counts = (int *)malloc(bin_count * sizeof(float));
bin_maxes = (float *)malloc(data_count * sizeof(float));
intermediateBinCounts = (int *)malloc(bin_count * thread_count * sizeof(int));
int lastElement = 0;
struct privateDataInfo s1[thread_count];
generateData();
}
void generateData() {
printf("%fn", max_meas);
printf("%f", min_meas);
}

提前谢谢你。

This

max_meas = 20;
max_meas = 5;

应该是这个

max_meas = 20;
min_meas = 5;

相关内容

  • 没有找到相关文章

最新更新