[问题]Linux C......

软件和网站开发以及相关技术探讨
回复
sjbird331
帖子: 70
注册时间: 2008-05-14 10:08

[问题]Linux C......

#1

帖子 sjbird331 » 2008-07-11 16:29

今天在Linux下写传址的程序,没想到竟然和VC下的差别那么多,下面就是我用vim写的程序:
#include <stdio.h>

void f(int &a)
{
a = 3;
}

int main()
{
int i;
f(i);
printf("%d\n",i);
return 0;
}

用gcc编译后,提示错误:error: expected ';', ',' , or ')' before '&' token
可是当我在VC中编写源程序为:
#include <iostream.h>

void f(int &a)
{
a = 3;
}

void main()
{
int i;
f(i);
cout << i << "\n";
}
VC却显示了 3
我很纳闷,难道我用的不是标准C吗?请教论坛上的高手,谢谢
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#2

帖子 BigSnake.NET » 2008-07-11 16:32

LZ 在写 C 还是 C++ 。。
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#3

帖子 bones7456 » 2008-07-11 16:34

BigSnake.NET 写了:LZ 在写 C 还是 C++ 。。
关注我的blog: ε==3
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

#4

帖子 solcomo » 2008-07-11 16:38

用g++
头像
kofshower
帖子: 1343
注册时间: 2007-03-13 11:23
联系:

Re: [问题]Linux C......

#5

帖子 kofshower » 2008-07-11 19:47

sjbird331 写了:今天在Linux下写传址的程序,没想到竟然和VC下的差别那么多,下面就是我用vim写的程序:
#include <stdio.h>

void f(int &a)
{
a = 3;
}

int main()
{
int i;
f(i);
printf("%d\n",i);
return 0;
}

用gcc编译后,提示错误:error: expected ';', ',' , or ')' before '&' token
可是当我在VC中编写源程序为:
#include <iostream.h>

void f(int &a)
{
a = 3;
}

void main()
{
int i;
f(i);
cout << i << "\n";
}
VC却显示了 3
我很纳闷,难道我用的不是标准C吗?请教论坛上的高手,谢谢
VC g++两边写的都可以作为反面教材
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
头像
yjcong
帖子: 2470
注册时间: 2006-02-28 3:11

Re: [问题]Linux C......

#6

帖子 yjcong » 2008-07-11 20:13

kofshower 写了:
sjbird331 写了:今天在Linux下写传址的程序,没想到竟然和VC下的差别那么多,下面就是我用vim写的程序:
#include <stdio.h>

void f(int &a)
{
a = 3;
}

int main()
{
int i;
f(i);
printf("%d\n",i);
return 0;
}

用gcc编译后,提示错误:error: expected ';', ',' , or ')' before '&' token
可是当我在VC中编写源程序为:
#include <iostream.h>

void f(int &a)
{
a = 3;
}

void main()
{
int i;
f(i);
cout << i << "\n";
}
VC却显示了 3
我很纳闷,难道我用的不是标准C吗?请教论坛上的高手,谢谢
VC g++两边写的都可以作为反面教材
lz被批判的太.....
一梦三年,
松风依旧,
萝月何曾老.


灵幽听微, 谁观玉颜?
灼灼春华, 绿叶含丹.
头像
kofshower
帖子: 1343
注册时间: 2007-03-13 11:23
联系:

#7

帖子 kofshower » 2008-07-11 20:44

一直赞成实践的啊。可是起码也要把书看了一遍再说啊。
建议看看The C++ Programming Language 和 The C Programming Language。熟悉其他语言的话看看例子和思考题就ok了
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
sjbird331
帖子: 70
注册时间: 2008-05-14 10:08

#8

帖子 sjbird331 » 2008-07-11 21:09

谢谢大家的教诲,但是我还是不明白,我的前段程序难道不能称为LinuxC吗?最近也不知道该找一本什么样的书作为LinuxC的资料,刚才winodws下转过来实在有点不适应 ^_^
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#9

帖子 BigSnake.NET » 2008-07-11 21:11

C 是没有传引用的,C++ 才有
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
kofshower
帖子: 1343
注册时间: 2007-03-13 11:23
联系:

#10

帖子 kofshower » 2008-07-11 21:14

噢 推荐鱼头书 和 K&C,其实ISO c的话和平台无关,windows那个c++那样些有一半的几率是不成的
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
sjbird331
帖子: 70
注册时间: 2008-05-14 10:08

#11

帖子 sjbird331 » 2008-07-11 21:28

难怪我下午老是gcc不行,可惜机子上是Ubuntu不是XP,所以觉得自己非常菜鸟,一切都得从新开始的 呵呵 希望大家有空QQ群聊 群号:65456531
回复