跪求利用共用体编写的C51单片机C语言程序例子,最好有祥细的程序讲解。谢了。

对于一楼这个吊毛我是相当的无语的,好好的你跑来添什么乱,你有问题啊?

//共用体其实有时也会用到,特别是RAM不够的时候,我们可以定义一个union,一会把它当做这种类型的变量用,一会又作另外的变量用,当然要前面一个变量不用才能当另外类型变量用,
As an alternative, you may use the following union to store floating-point values.

union f {
float f; /* Floating-point value */
unsigned long ul; /* Unsigned long value */
};

This union contains a float and an unsigned long in order to perform floating-point math operations and to respond to the IEEE error states.

For example:

#define NaN 0xFFFFFFFF /* Not a number (error) */
#define plusINF 0x7F800000 /* Positive overflow */
#define minusINF 0xFF800000 /* Negative overflow */

union f {
float f; /* Floating-point value */
unsigned long ul; /* Unsigned long value */
};

void main (void) {
float a, b;
union f x;

x.f = a * b;
if (x.ul == NaN || x.ul == plusINF || x.ul == minusINF) {
/* handle the error */
}
else {
/* result is correct */
}
}

Copyright (c) Keil Software, Inc. and Keil Elektronik GmbH. All rights reserved.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-05-17
哎...不要动不动就说跪,好不好!年纪轻轻的,老是想着给人跪,不就是一个共用体的用法嘛,有那么夸张嘛,网上随便一搜就有大把,已经讲得很详细了,只要你用点心,就一定能掌握它的用法。哎...操弟要我怎么说你呢...十天学会单片机 不知你看的怎样了... 平时少看点那种片...不知十天还剩下几天...
第2个回答  2012-11-15
使用共用体多数情况是为了灵活的访问自己所定义的变量。
第3个回答  2009-05-18
现在没有,有了一定告诉你的
相似回答