咨询一个glibc中strcat的实现的一个疑问

zjtzlqr 2014-09-17 11:28:27
/* Append SRC on the end of DEST. */
char *
strcat (dest, src)
char *dest;
const char *src;
{
char *s1 = dest;
const char *s2 = src;
reg_char c;

/* Find the end of the string. */
do
c = *s1++;
while (c != '\0');

/* Make S1 point before the next character, so we can increment
it while memory is read (wins on pipelined cpus). */
s1 -= 2;

do
{
c = *s2++;
*++s1 = c;
}
while (c != '\0');

return dest;
}


在glibc 的sting文件下的strcat.c源代码中为什么函数的定义可以是下面的这种形式,我模仿一个函数却不能编译通过

strcat (dest, src)
char *dest;



模仿的函数如下
#include <stdio.h>
int strhhh (a)
int *a;
{
printf("a is(%u)",*a);
return 1;



int main(void)
{
int b =3;
strhhh(&b);
}
const char *src;
...全文
88 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-09-18
  • 打赏
  • 举报
回复
Obsolete Forms of Function Declarations and Definitions The old-style function declarations and definitions use slightly different rules for declaring parameters than the syntax recommended by the ANSI C standard. First, the old-style declarations don’t have a parameter list. Second, in the function definition, the parameters are listed, but their types are not declared in the parameter list. The type declarations precede the compound statement constituting the function body. The old-style syntax is obsolete and should not be used in new code. Code using the old-style syntax is still supported, however. This example illustrates the obsolete forms of declarations and definitions: double old_style(); /* Obsolete function declaration */ double alt_style( a , real ) /* Obsolete function definition */ double *real; int a; { return ( *real + a ) ; } Functions returning an integer or pointer with the same size as an int are not required to have a declaration although the declaration is recommended. To comply with the ANSI C standard, old-style function declarations using an ellipsis now generate an error when compiling with the /Za option and a level 4 warning when compiling with /Ze. For example: void funct1( a, ... ) /* Generates a warning under /Ze or */ int a; /* an error when compiling with /Za */ { } You should rewrite this declaration as a prototype: void funct1( int a, ... ) { } Old-style function declarations also generate warnings if you subsequently declare or define the same function with either an ellipsis or a parameter with a type that is not the same as its promoted type. The next section, C Function Definitions, shows the syntax for function definitions, including the old-style syntax. The nonterminal for the list of parameters in the old-style syntax is identifier-list.
brookmill 2014-09-17
  • 打赏
  • 举报
回复
不要纠结了,这是二十多年前的语法,早就淘汰了。 int strhhh (a) int *a; { ...... 这个相当于 int strhhh (int *a) { ...

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧