LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 3257|回复: 33

About gcc in Mandrake 9.0!!!

[复制链接]
发表于 2002-11-1 22:12:57 | 显示全部楼层 |阅读模式
The linux i used now is the Mandrake 9.0!
i use the linux to practise the C pro.

i found th GCC version is 3.2,and the version i used in Red Hat 7.2 is older.

And i found ,the program i maked as the book,i can make it to program sucessfully in Red Hat 7.2,but have some problem in Mandrake 9.0 .

i am confused,and i can't solved it .


i hope the gaoshou can tell me the difference between them!

it's so serious!

i am auxious!     Thank you!
发表于 2002-11-2 08:53:26 | 显示全部楼层
把编译时的错误贴出来让大家扶看看.
 楼主| 发表于 2002-11-2 09:18:15 | 显示全部楼层
好的!
 楼主| 发表于 2002-11-2 09:27:30 | 显示全部楼层
[smallmantou@Smallmantou linuxC]$ gcc sort.c
sort.c:2:1: warning: "NULL" redefined
In file included from /usr/include/_G_config.h:14,
                 from /usr/include/libio.h:32,
                 from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/include/stdio.h:74,
                 from sort.c:1:
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/include/stddef.h:369:1: warning: this is the location of the previous definition
sort.c: In function `creat':
sort.c:36: parse error before '!' token
sort.c: At top level:
sort.c:44: parse error before '->' token
sort.c: In function `insert':
sort.c:51: `pa2' undeclared (first use in this function)
sort.c:51: (Each undeclared identifier is reported only once
sort.c:51: for each function it appears in.)
sort.c:54: parse error before '!' token
sort.c:68: parse error before '!' token
sort.c:68: parse error before '!' token
sort.c: In function `print':
sort.c:80: parse error before '!' token
sort.c: At top level:
sort.c:85: parse error before "while"
 楼主| 发表于 2002-11-2 09:28:30 | 显示全部楼层

the C detail

[smallmantou@Smallmantou linuxC]$ cat sort.c
#include <stdio.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{ long num;
  int score;
  struct student * next;
};
struct student listA,listB;
int n,sum=0;

main()
{struct student * creat(void);
struct student * insert(struct student *,struct student *);
void print(struct student *);
struct student * ahead,* bhead,* abh;
printf("\nInput list a:\n");
ahead=creat();
sum=sum+n;
printf("\nInput list b:\n");
bhead=creat();
sum=sum+n;
abh=insert(ahead,bhead);
print(abh);
}


struct student * creat(void)
{struct student * p1,* p2,* head;
n=0;
p1=p2=(struct student * )malloc(LEN);
printf("Input number & scores of student:\n");
printf("If number is 0,stop inputing.\n");
scanf("%ld,%d",&p1->num,&p1->score);
head=NULL;
while(p1->num! =0)
     {n=n+1;
      if(n==1)head=p1;
      else p2->next=p1;
      p2=p1;
      p1=(struct student * )malloc(LEN);
      scanf("%ld,%d",&p1->num,&p1->score);
     }
p2->next=NULL;
return(head);
}


struct student * insert(struct student * ah,struct student * bh)
{struct student * pa1,* p2,* pb1,* pb2;
pa2=pa1=ah;
pb2=pb1=bh;
do
   {while((pb1->num>pa1->num) && (pa1->next! =NULL))
       {pa2=pa1;
        pa1=pa1->next;
       }
    if(pb1->num<=pa1->num)
       {if(ah==pa1)
        ah=pb1;
        else pa2->next=pb1;
        pb1=pb1->next;
        pb2->next=pa1;
        pa2=pb2;
        pb2=pb1;
       }
   }
while((pa1->next! =NULL)||(pa1==NULL && pb1! =NULL));
    if((pb1->num>pa1->num) && (pa1->next==NULL))
        pa1->next=pb1;
return(ah);
}



void print(struct student * head)
{struct student * p;
printf("\nThese are %d records:\n",sum);
p=head;
if(p! =NULL)
   do
     {printf("%ld %d\n",p->num,p->score);
      p=p->next;
     }
   while(p! =NULL);
}
 楼主| 发表于 2002-11-2 09:29:25 | 显示全部楼层

the version of GCC

[smallmantou@Smallmantou linuxC]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/specs
Configured with: ../configure --prefix=/usr --libdir=/usr/lib --with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --enable-long-long --enable-__cxa_atexit --enable-languages=c,c++,ada,f77,objc,java --host=i586-mandrake-linux-gnu --with-system-zlib
Thread model: posix
gcc version 3.2 (Mandrake Linux 9.0 3.2-1mdk)
发表于 2002-11-2 09:40:08 | 显示全部楼层
> #define NULL 0

Delete this line. Or, if you really want, code like this:

#ifndef NULL
#define NULL 0
#endif  /* NULL */

> main()

Please use
int main()

> while(p1->num! =0)

!= is an operator, can not be separated. Use

while(p1->num != 0)

Please change these and compile again.
 楼主| 发表于 2002-11-2 12:33:03 | 显示全部楼层
能用中文说明一下,这个版本的gcc和原来的有什么不同吗?

版本升级了,是不是有些要注意了?

#define NULL 0
#endif /* NULL */

int main()

能解释一下为什么吗?这个可是书上的原程序呀! 应该没有错的呀
我在gcc 2.9的版本中怎么没有这么多的问题??

还希望高手帮忙,救我救到低,小弟不胜感激!!
 楼主| 发表于 2002-11-2 12:55:26 | 显示全部楼层
It's can run now!  Thank you!
but  there some information come up!   there is smoe warning,and explain the LIB adn .H  directory where is!
is there some affect??



[smallmantou@Smallmantou linuxC]$ gcc sort.c
sort.c:3:1: warning: "NULL" redefined
In file included from /usr/include/_G_config.h:14,
                 from /usr/include/libio.h:32,
                 from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/include/stdio.h:74,
                 from sort.c:1:
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/include/stddef.h:369:1: warning: this is the location of the previous definition
 楼主| 发表于 2002-11-2 13:09:09 | 显示全部楼层
/usr/include/_G_config.h:14,
/usr/include/libio.h:32
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/include/stdio.h:74,
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/include/stddef.h:369:1: warning: this is the location of the previous definition


this i have seen,and i think is the answer for the difference about the different version of th GCC in   
Mandrake LInux,

because i am the fresh man for the C pro.  so in this
GCC pro making system ,and in the so new version ,i am coufused ,
  i hope the 高原之狼 daxia,can be patient for explaining about the point what i should be attentioned in the GCC 3.2!!!

thank you!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表