avatar
C*Q
1
【 以下文字转载自 Immigration 讨论区 】
发信人: CandyQQ (甜甜糖), 信区: Immigration
标 题: 配偶加入485申请的问题
发信站: BBS 未名空间站 (Wed Oct 29 21:40:13 2008)
比如说主申请人的绿卡申请priority date是2006年10月份,在2007年7月份那拨已经提
交了485. 如果现在马上结婚的话,配偶可不可以也提交485? (考虑到现在排期只有排
到2004年)
avatar
i*p
2
char s1[] = "Hello ";
char s2[] = "world";
char *s3;
s3 = strcat(s1, s2);
It is Ok. Both s1 and s3 will be "Hello world".
char *s1 = "Hello ";
char s2[] = "world";
char *s3;
s3 = strcat(s1, s2);
It is runtime error. Can you explain?
avatar
s*x
3
同问~ thx
avatar
P*e
4
strcat(char*, const char*)
s1必须是char *;
char *s1 = "hello";
s1是指向 const char*的,因为s1是desti

【在 i**p 的大作中提到】
: char s1[] = "Hello ";
: char s2[] = "world";
: char *s3;
: s3 = strcat(s1, s2);
: It is Ok. Both s1 and s3 will be "Hello world".
: char *s1 = "Hello ";
: char s2[] = "world";
: char *s3;
: s3 = strcat(s1, s2);
: It is runtime error. Can you explain?

avatar
i*p
5
Do you mean
char *s1 = "hello"; s1 points to a const string?

【在 P********e 的大作中提到】
: strcat(char*, const char*)
: s1必须是char *;
: char *s1 = "hello";
: s1是指向 const char*的,因为s1是desti

avatar
P*e
6


【在 i**p 的大作中提到】
: Do you mean
: char *s1 = "hello"; s1 points to a const string?

avatar
d*2
7
you totally mess up the memory. s1 must be allocated with enough space first
.
avatar
i*p
8
How about
char s1[] = "hello";
I think the size of s1 has been set to 6. how does it work?

【在 P********e 的大作中提到】
: 恩
avatar
i*p
9
How does it work?
char s1[] = "Hello ";
char s2[] = "world";
char *s3;
s3 = strcat(s1, s2);
Both s1 and s3 will be "Hello world".

【在 i**p 的大作中提到】
: How about
: char s1[] = "hello";
: I think the size of s1 has been set to 6. how does it work?

avatar
d*2
10

it does not work. any c programmer writes this way should be hanged.

【在 i**p 的大作中提到】
: How does it work?
: char s1[] = "Hello ";
: char s2[] = "world";
: char *s3;
: s3 = strcat(s1, s2);
: Both s1 and s3 will be "Hello world".

avatar
i*p
11
I run it by VC. It prints both s1 and s3 as "hello world".

【在 d****2 的大作中提到】
:
: it does not work. any c programmer writes this way should be hanged.

avatar
t*t
12
运行结果正确不代表你的程序就是正确的

【在 i**p 的大作中提到】
: I run it by VC. It prints both s1 and s3 as "hello world".
avatar
i*p
13
then what tool can help us to find this programming error?

【在 t****t 的大作中提到】
: 运行结果正确不代表你的程序就是正确的
avatar
d*2
14

that is a good research question. MSFT will be very interested to fix their
crappy code base.

【在 i**p 的大作中提到】
: then what tool can help us to find this programming error?
avatar
i*p
15
A good compiler should at least give a waring, but VC++ does not.

their

【在 d****2 的大作中提到】
:
: that is a good research question. MSFT will be very interested to fix their
: crappy code base.

avatar
d*2
16

google buffer overflow.

【在 i**p 的大作中提到】
: A good compiler should at least give a waring, but VC++ does not.
:
: their

avatar
c*t
17
Just forget using strcat function. sprintf and strcpy are
less error prone.

【在 i**p 的大作中提到】
: A good compiler should at least give a waring, but VC++ does not.
:
: their

avatar
t*t
18
name a compiler that will give a warning for this.

【在 i**p 的大作中提到】
: A good compiler should at least give a waring, but VC++ does not.
:
: their

avatar
m*e
19

It's not ok. You just got lucky.

【在 i**p 的大作中提到】
: A good compiler should at least give a waring, but VC++ does not.
:
: their

avatar
O*d
20
如果你把s1和s2中间插一个,看看能不能运行。再看一看_s1变成了什么。
char s1[] = "Hello ";
char _s1[] = "whatever";
char s2[] = "world";
char *s3;
s3 = strcat(s1, s2);
printf("s1 %s _s1 %s\n", s1, _s1);

【在 i**p 的大作中提到】
: I run it by VC. It prints both s1 and s3 as "hello world".
avatar
i*p
21
I know what all of you talk about. see my original post. My qustion is s1[]
and *s1 have different result, which means *s1 is more protective than s1[].
Why not make them the same?
char s1[] = "Hello ";
char *s1 = "Hello ";

【在 O*******d 的大作中提到】
: 如果你把s1和s2中间插一个,看看能不能运行。再看一看_s1变成了什么。
: char s1[] = "Hello ";
: char _s1[] = "whatever";
: char s2[] = "world";
: char *s3;
: s3 = strcat(s1, s2);
: printf("s1 %s _s1 %s\n", s1, _s1);

avatar
d*2
22
char [] has space allocated on stack
char * is a pointer to static text area, write protected.
BTW, char [] and char * are different thing. Compiler does some translation
for you so you won't notice the difference most of time. Try sizeof(s1) in
both cases and you will know why.
avatar
i*p
23
Of course, s1[] and *s1 are different. I have seen lots of programmer tried
to do something like “strcpy (s2, s1, sizeof(s1))” with s1 defined as *s1.
When is happened, I partly blame the programmer and mostly blame why C does
not do something to prevent this from the beginning or a latter improvement
. Anyway, this is a dangerous pitfall for a beginner and mostly to be an
interview question.
For the strcat(), it is much easier to generate a compiler warning or
runtime error for s1[] than *s1, b

【在 d****2 的大作中提到】
: char [] has space allocated on stack
: char * is a pointer to static text area, write protected.
: BTW, char [] and char * are different thing. Compiler does some translation
: for you so you won't notice the difference most of time. Try sizeof(s1) in
: both cases and you will know why.

avatar
t*t
24
在你指责一个语言有这样那样的问题的时候, 有必要考虑语言设计时的历史环境. 为了
保持高速度, C语言里本来就没有数组边界检查, 更何况数组在函数调用里自动退化为指
针,数组尺寸信息早就没有了.
嫌C语言不安全的话,有很多更安全的语言可以用.就算是C++, 也有string class.
不过, 会在strcpy()里写上三个参数的, 可以想见你连门都没入. (FYI, 有三个参数的
那个叫做strncpy().) 门都没入的人还是虚心一点的好, 不要连纸上谈兵都谈不来,被人
笑掉大牙.

tried
s1.
does
improvement
an

【在 i**p 的大作中提到】
: Of course, s1[] and *s1 are different. I have seen lots of programmer tried
: to do something like “strcpy (s2, s1, sizeof(s1))” with s1 defined as *s1.
: When is happened, I partly blame the programmer and mostly blame why C does
: not do something to prevent this from the beginning or a latter improvement
: . Anyway, this is a dangerous pitfall for a beginner and mostly to be an
: interview question.
: For the strcat(), it is much easier to generate a compiler warning or
: runtime error for s1[] than *s1, b

avatar
d*2
25
funny, OP is asking beginner questions yet acts like a pro wannabe. no wonder such forums are boring. compiler is harder than you think.
avatar
i*p
26
小屁孩拣了个大包子,乐得找不到了北。老哥虽民工出身,码砖的事早就不干了。听说
过大博士不知道 10000000是负几吗?没听说过只能说你太嫩。我到是在民工
学徒其间老听到同道笑话师傅打字没他快,你也就和他有一比了。

为指
被人

【在 t****t 的大作中提到】
: 在你指责一个语言有这样那样的问题的时候, 有必要考虑语言设计时的历史环境. 为了
: 保持高速度, C语言里本来就没有数组边界检查, 更何况数组在函数调用里自动退化为指
: 针,数组尺寸信息早就没有了.
: 嫌C语言不安全的话,有很多更安全的语言可以用.就算是C++, 也有string class.
: 不过, 会在strcpy()里写上三个参数的, 可以想见你连门都没入. (FYI, 有三个参数的
: 那个叫做strncpy().) 门都没入的人还是虚心一点的好, 不要连纸上谈兵都谈不来,被人
: 笑掉大牙.
:
: tried
: s1.

avatar
m*e
27
Please take your troll somewhere else.

【在 i**p 的大作中提到】
: 小屁孩拣了个大包子,乐得找不到了北。老哥虽民工出身,码砖的事早就不干了。听说
: 过大博士不知道 10000000是负几吗?没听说过只能说你太嫩。我到是在民工
: 学徒其间老听到同道笑话师傅打字没他快,你也就和他有一比了。
:
: 为指
: 被人

avatar
t*t
28
虽然不知道你说的是啥,不过常来的都知道,我不是靠写程序吃饭的

【在 i**p 的大作中提到】
: 小屁孩拣了个大包子,乐得找不到了北。老哥虽民工出身,码砖的事早就不干了。听说
: 过大博士不知道 10000000是负几吗?没听说过只能说你太嫩。我到是在民工
: 学徒其间老听到同道笑话师傅打字没他快,你也就和他有一比了。
:
: 为指
: 被人

avatar
n*t
29
你真是小母牛选美啊。

【在 i**p 的大作中提到】
: 小屁孩拣了个大包子,乐得找不到了北。老哥虽民工出身,码砖的事早就不干了。听说
: 过大博士不知道 10000000是负几吗?没听说过只能说你太嫩。我到是在民工
: 学徒其间老听到同道笑话师傅打字没他快,你也就和他有一比了。
:
: 为指
: 被人

avatar
i*p
30
Please understand it is not shame to 靠写程序吃饭. My point is you pay more
attention to my example strcpy. Thank you anyway since you posted a lot for
this topic even though I do not agree most of your answer.

【在 t****t 的大作中提到】
: 虽然不知道你说的是啥,不过常来的都知道,我不是靠写程序吃饭的
avatar
f*y
31
You guys don't mention s2 at all? It probably will be "orld".

【在 i**p 的大作中提到】
: Please understand it is not shame to 靠写程序吃饭. My point is you pay more
: attention to my example strcpy. Thank you anyway since you posted a lot for
: this topic even though I do not agree most of your answer.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。