C:如何检查是否结构初始化? [英] C: How to check if a structure is initialized?

查看:179
本文介绍了C:如何检查是否结构初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的数据结构实现的表。我的code的一个重要的块看起来像这样(H是一种数据结构,表是用于存储其他结构表):

I have a table that I'm implementing with data structures. An important block of my code looks like this(h is a data structure, table is a table that stores other structures):

(h->table[hash(key, h->size)]

虽然我的code运行时,有些表[I]的将被初始化,而有些则不是。每当我测试我的code对表[我]认为尚未初始化,我得到一个错误Valgrind的,基本上说,我不能与一个未初始化数组工作。

While my code is running, some table[i]'s will be initialized, and some aren't. Whenever I test my code on a table[i] that hasn't been initialized yet, I get a valgrind error which basically says I can't work with an uninitialized array.

我的问题是,我将如何检查,看看是否有一定H->表[i]的初始化或没有?

My question is, how would I check to see if a certain h->table[i] is initialized or not?

推荐答案

您不能。要解决此问题,总是使用它(即使所有的初始化并设置该结构为已知的空白/不填充状态)之前初始化结构。

You can't. To fix the problem, always initialize the struct before using it (even if all the initialization does is set the struct to a known "blank"/"not populated" state).

这篇关于C:如何检查是否结构初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆