如何准确地找出uint64_t类型的C中ADT向量的长度?
How exactly find out length of ADT vector in C which is type of uint64_t?
我正在尝试找出如何在 C 中找到 uint64_t 的 ADT 数组类型的长度。
提供查找数组长度功能的代码:
void func(uint64_t *arr , const char *restrict sep){
int size = sizeof(arr) / sizeof(arr[0]);
printf("Size of vektor: %d", size);
}
我无法更改任何变量,因为它被整个代码的创建者禁止我只能实现一些功能。
vector.h 文件中的代码
/* Exported types --------------------------------------------------------------------------------*/
/*! Data type that is stored in the vector. */
typedef uint64_t Vector_DataType_t;
/*! Structure that describes the vector. */
typedef struct {
/*! Internal pointer to allocated memory. */
Vector_DataType_t *items;
/*! Number of currently allocated cells. */
size_t size;
/*! Pointer to the next empty cell. */
Vector_DataType_t *next;
/*! Number of cells allocated during expanding. */
size_t alloc_step;
} Vector_t;
main.c 我想在其中实现功能的文件(我不能 post 这里整个 bcse 有超过 200 行)
int main(void)
{
bool run = true;
Vector_DataType_t n;
printf("Vector test program\n"
"Type the default size of array and the size of incrementation.\n"
"Size:\n");
Vector_t *vector;
{
size_t size;
if (io_utils_get("%zu", &size) == true) { // Change from "false" to true
return 0;
}
printf("Incrementation:\n");
size_t step;
if (io_utils_get("%zu", &step) == false) {
return 0;
}
vector = Vector_Create(size, step);
}
if (vector == NULL) {
printf("Memory for vector was not allocated successfully.\n");
return 0;
}
您找不到作为指针传递给函数的数组的大小。
编译器也无法知道它有多大
- 将长度作为参数传入
- 有标记值,0、-1、MAX_INT等
我忽略了你的代码非常混乱的事实,我假设你正在尝试这样做
注意注意====此代码不起作用===================
void func(uint64_t *arr , const char *restrict sep){
int size = sizeof(arr) / sizeof(arr[0]);
printf("Size of vektor: %d", size);
}
我正在尝试找出如何在 C 中找到 uint64_t 的 ADT 数组类型的长度。
提供查找数组长度功能的代码:
void func(uint64_t *arr , const char *restrict sep){
int size = sizeof(arr) / sizeof(arr[0]);
printf("Size of vektor: %d", size);
}
我无法更改任何变量,因为它被整个代码的创建者禁止我只能实现一些功能。
vector.h 文件中的代码
/* Exported types --------------------------------------------------------------------------------*/
/*! Data type that is stored in the vector. */
typedef uint64_t Vector_DataType_t;
/*! Structure that describes the vector. */
typedef struct {
/*! Internal pointer to allocated memory. */
Vector_DataType_t *items;
/*! Number of currently allocated cells. */
size_t size;
/*! Pointer to the next empty cell. */
Vector_DataType_t *next;
/*! Number of cells allocated during expanding. */
size_t alloc_step;
} Vector_t;
main.c 我想在其中实现功能的文件(我不能 post 这里整个 bcse 有超过 200 行)
int main(void)
{
bool run = true;
Vector_DataType_t n;
printf("Vector test program\n"
"Type the default size of array and the size of incrementation.\n"
"Size:\n");
Vector_t *vector;
{
size_t size;
if (io_utils_get("%zu", &size) == true) { // Change from "false" to true
return 0;
}
printf("Incrementation:\n");
size_t step;
if (io_utils_get("%zu", &step) == false) {
return 0;
}
vector = Vector_Create(size, step);
}
if (vector == NULL) {
printf("Memory for vector was not allocated successfully.\n");
return 0;
}
您找不到作为指针传递给函数的数组的大小。
编译器也无法知道它有多大
- 将长度作为参数传入
- 有标记值,0、-1、MAX_INT等
我忽略了你的代码非常混乱的事实,我假设你正在尝试这样做
注意注意====此代码不起作用===================
void func(uint64_t *arr , const char *restrict sep){
int size = sizeof(arr) / sizeof(arr[0]);
printf("Size of vektor: %d", size);
}