比较两个结构

编程入门 行业动态 更新时间:2024-10-10 07:21:38
本文介绍了比较两个结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

伙计们, 使用 " memcmp"这是比较两个结构是否相等的好方法。 ? 如果没有,可能与此相关的问题是什么?什么是 正确的 方法呢? 感谢您的帮助。

推荐答案

ju ***** *****@yahoo.co.in 说: 伙计们, 这是一个通过使用 " memcmp"来比较两个结构的平等性的好方法? Guys, Is it a good way to compare two structures for equality by using "memcmp" ?

No.

No.

如果没有,可能与此相关的问题是什么? If not, what could be the problems associated with this ?

填充字节,以及struct 成员指向的动态分配内存。

Padding bytes, and dynamically allocated memory pointed to by struct members.

这样做的正确方法是什么? And what is the correct method of doing this ?

int cmp(const struct T * a,const struct T * b); - Richard Heathfield< www.cpax.uk> 电邮:-www。 + rjh @ 谷歌用户:< www.cpax.uk/prg/writings/googly.php> Usenet是一个奇怪的放置" - dmr 1999年7月29日

int cmp(const struct T *a, const struct T *b); -- Richard Heathfield <www.cpax.uk> Email: -www. +rjh@ Google users: <www.cpax.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999

< ju ********** @ yahoo.co.inschrieb im Newsbeitrag news :11 ********************* @ w3g2000hsg.googlegrou ps ... <ju**********@yahoo.co.inschrieb im Newsbeitrag news:11*********************@w3g2000hsg.googlegrou ps... 伙计们, 使用 " memcmp"这是比较两个结构是否相等的好方法。 ? 如果没有,可能与此相关的问题是什么?什么是 正确的 方法呢? 感谢您的帮助。 Guys, Is it a good way to compare two structures for equality by using "memcmp" ? If not, what could be the problems associated with this ? And what is the correct method of doing this ? thanks for any help.

c-faq/ struct / compare.html

Richard Heathfield写道: Richard Heathfield wrote: ju ********** @ yahoo.co.in 说: >通过使用memcmp来比较两个结构的平等性是一种好方法吗? ? >Is it a good way to compare two structures for equality by using"memcmp" ?

No.

No.

>如果没有,可能与此相关的问题是什么? >If not, what could be the problems associated with this ?

填充字节,以及 结构成员指向的动态分配内存。

Padding bytes, and dynamically allocated memory pointed to by struct members.

>这样做的正确方法是什么? >And what is the correct method of doing this ?

int cmp(const struct T * a,const struct T * b);

int cmp(const struct T *a, const struct T *b);

哪个应解决(非常粗略): for(c =每个组件的a){ if((a-> c)!=(b-> c))return 0; / * unequal * / } 返回1; / * ie结构相等* / 这意味着你必须编写一个cmp()每种结构类型。你可能需要 来解析嵌入式指针。 br /> - Chuck F(cinefalconer at maineline dot net) 可用于咨询/临时嵌入式和系统。 < cbfalconer.home.att> - 通过 www.teranews

Which should resolve to (very roughly}: for (c = eachcomponentof a) { if ((a->c) != (b->c)) return 0; /* unequal */ } return 1; /* i.e. structures equal */ Which means you have to write a cmp() each structure type. You may have to resolve embedded pointers. -- Chuck F (cbfalconer at maineline dot net) Available for consulting/temporary embedded and systems. <cbfalconer.home.att> -- Posted via a free Usenet account from www.teranews

更多推荐

比较两个结构

本文发布于:2023-11-29 04:25:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645267.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   结构

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!