funcA.c
直接上代碼:
#include "stdio.h"
struct NODE{
int value;
struct NODE *nextNode;
struct NODE *preNode;
};
typedef struct NODE sNODE;
int main()
{
printf("main\n");
sNODE NodeBrightness;
sNODE NodeContrast;
sNODE NodeSharp;
NodeBrightness.value = 50;
NodeBrightness.nextNode = NodeContrast;
printf("Brightness = %d\n", NodeBrightness.value);
printf("Contrast = %d\n", NodeContrast.value);
printf("Sharpness = %d\n", NodeSharp.value);
printf("Brightness next value = %d\n", NodeBrightness.nextNode->value);
return 0;
}
編譯:
$ gcc -o NextNode funcA.c
編譯錯誤:
funcA.c:22:29: error: assigning to 'struct NODE *' from incompatible type 'sNODE' (aka 'struct NODE'); take the address
with &
NodeBrightness.nextNode = NodeContrast;
^ ~~~~~~~~~~~~
&
1 error generated.
NodeBrightness.nextNode = &NodeContrast;
再次編譯:
$ gcc -o NextNode funcA.c
成功,執行:./NextNode
輸出:
main
Brightness = 50
Contrast = 0
Sharpness = 0
Brightness next value = 0