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

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

问题描述

我有一个要使用数据结构实现的表格。我的代码的重要部分如下所示(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)]

虽然我的代码正在运行时,某些表[i]将被初始化,而某些未初始化。每当我在尚未初始化的表[i]上测试代码时,我都会收到一个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-> table [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).

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

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