当前位置:首页 » 编程语言 » c语言函数别名
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言函数别名

发布时间: 2022-01-18 21:50:23

1. c语言中的函数名与文件名的区别;

命名规则基本一样,但函数名一般有返回类型,如int char long void等,而文件名无返回类型,并且一般要带扩展名,如.txt .doc等。

2. 在c语言中,函数可以任意命名吗

函数名也是标示符,要符合标示符的命令规则。

_或者字符开头,只能包含_、字母和数字。

重名的函数要求参数不能相同。

3. C语言中 函数名()在括号中的定义和在函数程序中的定义有什么不一样吗

完全不一样,void dfljs(int a)中的a是要向函数传递的变量,而b只是调用函数里所用的变量。不明白再问我。

4. C语言中!typedef函数是用来取别名的对吧 取别名有什么用干嘛要取别名就用原来的名字不好

例如
typedef struct ABC{
...

}abc;
那么定义结构体变量的时候struct ABC 就不用全部输出来了,用abc就可以了

5. C语言主函数的函数名是什么意思

1,先不用理解太多,只要知道main函数是程序入口地址,也就是说每次写程序都得有一个main(),然后多多练习程序,有些概念时间久了自然会理解。多练习就好,只是每次写程序都要有一个main(),这一点先记住就好。记住,要想学好,就得多练,多写程序,刚开始不会写,可以照抄程序,然后做少量修改,改着改着,你就明白程序怎么写了。
2,关于数学,英文或是其他学科。
其实c语言,也只是一种工具,一种和计算机打交道的工具。就想英语,汉语一样。只是英语、汉语都是和人打交道的。而计算机听不懂这些,你得用他能理解的语言来和他沟通,这就是计算机语言。这里边是需要一点英文,但不多,我有一个没学过英文的同学(他主修俄语),照样程序写的很好。数学嘛,这个就得看你的应用方向了。
参考资料:http://iask.sina.com.cn/b/18581538.html

C语言
按照C99标准的规定,C语言的main函数如下:
int main(
void){/*网络示例代码*/}//整数类型主函数(无类型)

或者
int main(intargc,
char*argv[]){/*网络示例代码*/}//整数类型主函数(整数类型统计参数个数,字符类型*
数组指针至字符[])

6. c语言的函数名可以随便定义么随便弄些字母就可以把这个定义成函数么

可以根据你的使用需要来自定义函数

void名称()
{
//这种定义是不需要有返回值和参数,一般用来执行一些不用传参的功能
}
int名称()
{
return数字;
//这种函数在执行之后会有一个int型返回参数.
}

7. c语言函数定义时函数名和代码中变量名可以一样吗

可以同名。
形参的作用域只在它所在的函数中,
在函数ili9481_set_io_port中ctl_inf是形参,
全局变量ctl_inf被屏蔽。

8. 在C语言中有那些函数名

仅仅为了获取函数名,就在函数体中嵌入硬编码的字符串,这种方法单调乏味还易导致错误,不如看一下怎样使用新的C99特性,在程序运行时获取函数名吧.对象反射库、调试工具及代码分析器,经常会需要在运行时访问函数的名称,直到不久前,唯一能完成此项任务并且可移植的方法,是手工在函数体内嵌入一个带有该函数名的硬编码字符串,不必说,这种方法非常单调无奇,并且容易导致错误。本文将要演示怎样使用新的C99特性,在运行时获取函数名。

那么怎样以编程的方式从当前运行的函数中得到函数名呢?

答案是:使用__FUNCTION__ 及相关宏。

引出问题

通常,在调试中最让人心烦的阶段,是不断地检查是否已调用了特定的函数。对此问题的解决方法,一般是添加一个cout或printf()——如果你使用C语言,如下所示:

void myfunc()
{
cout<<"myfunc()"<<endl;
//其他代码
}

通常在一个典型的工程中,会包含有数千个函数,要在每个函数中都加入一条这样的输出语句,无疑难过上“蜀山”啊,因此,需要有一种机制,可以自动地完成这项操作。

获取函数名

作为一个C++程序员,可能经常遇到 __TIME__、__FILE__、__DATE__ 这样的宏,它们会在编译时,分别转换为包含编译时间、处理的转换单元名称及当前时间的字符串。

在最新的ISO C标准中,如大家所知的C99,加入了另一个有用的、类似宏的表达式__func__,其会报告未修饰过的(也就是未裁剪过的)、正在被访问的函数名。请注意,__func__不是一个宏,因为预处理器对此函数一无所知;相反,它是作为一个隐式声明的常量字符数组实现的:

static const char __func__[] = "function-name";

在function-name处,为实际的函数名。为激活此特性,某些编译器需要使用特定的编译标志,请查看相应的编译器文档,以获取具体的资料。

有了它,我们可免去大多数通过手工修改,来显示函数名的苦差事,以上的例子可如下所示进行重写:

void myfunc()
{
cout<<"__FUNCTION__"<<endl;
}

官方C99标准为此目的定义的__func__标识符,确实值得大家关注,然而,ISO C++却不完全支持所有的C99扩展,因此,大多数的编译器提供商都使用 __FUNCTION__ 取而代之,而 __FUNCTION__ 通常是一个定义为 __func__ 的宏,之所以使用这个名字,是因为它已受到了大多数的广泛支持。

在Visual Studio 2005中,默认情况下,此特性是激活的,但不能与/EP和/P编译选项同时使用。请注意在IDE环境中,不能识别__func__ ,而要用__FUNCTION__ 代替。

Comeau的用户也应使用 __FUNCTION__ ,而不是 __func__ 。

C++ BuilderX的用户则应使用稍稍不同的名字:__FUNC__ 。

GCC 3.0及更高的版本同时支持 __func__ 和__FUNCTION__ 。

一旦可自动获取当前函数名,你可以定义一个如下所示显示任何函数名的函数:

void show_name(const char * name)
{
cout<<name<<endl;
}

void myfunc()
{
show_name(__FUNCTION__); //输出:myfunc
}

void foo()
{
show_name(__FUNCTION__); //输出:foo
}

因为 __FUNCTION__ 会在函数大括号开始之后就立即初始化,所以,foo()及myfunc()函数可在参数列表中安全地使用它,而不用担心重载。

签名与修饰名

__FUNCTION__ 特性最初是为C语言设计的,然而,C++程序员也会经常需要有关他们函数的额外信息,在Visual Studio 2005中,还支持另外两种非标准的扩展特性:__FUNCDNAME__ 与 __FUNCSIG__ ,其分别转译为一个函数的修饰名与签名。函数的修饰名非常有用,例如,在你想要检查两个编译器是否共享同样的ABI时,就可派得上用场,另外,它还能帮助你破解那些含义模糊的链接错误,甚至还可用它从一个DLL中调用另一个用C++链接的函数。在下例中,show_name()报告了函数的修饰名:

void myfunc()
{
show_name(__FUNCDNAME__); //输出:?myfunc@@YAXXZ
}

一个函数的签名由函数名、参数列表、返回类型、内含的命名空间组成。如果它是一个成员函数,它的类名和const/volatile限定符也将是签名的一部分。以下的代码演示了一个独立的函数与一个const成员函数签名间的不同之处,两个函数的名称、返回类型、参数完全相同:

void myfunc()
{
show_name(__FUNCSIG__); // void __cdecl myfunc(void)
}

struct S
{
void myfunc() const
{
show_name(__FUNCSIG__); //void __thiscall S::myfunc(void) const
}
};

9. C语言函数列表

函数名: abort
功 能: 异常终止一个进程
用 法: void abort(void);
程序例:
#include <stdio.h>
#include <stdlib.h> int main(void)
{
printf("Calling abort()\n");
abort();
return 0; /* This is never reached */
}
函数名: abs
功 能: 求整数的绝对值
用 法: int abs(int i);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
int number = -1234; printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
函数名: absread, abswirte
功 能: 绝对磁盘扇区读、写数据
用 法: int absread(int drive, int nsects, int sectno, void *buffer);
int abswrite(int drive, int nsects, in tsectno, void *buffer);
程序例:
/* absread example */ #include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h> int main(void)
{
int i, strt, ch_out, sector;
char buf[512]; printf("Insert a diskette into drive A and press any key\n");
getch();
sector = 0;
if (absread(0, 1, sector, &buf) != 0)
{
perror("Disk problem");
exit(1);
}
printf("Read OK\n");
strt = 3;
for (i=0; i<80; i++)
{
ch_out = buf[strt+i];
putchar(ch_out);
}
printf("\n");
return(0);
}
函数名: access
功 能: 确定文件的访问权限
用 法: int access(const char *filename, int amode);
程序例:
#include <stdio.h>
#include <io.h> int file_exists(char *filename); int main(void)
{
printf("Does NOTEXIST.FIL exist: %s\n",
file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
return 0;
} int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
函数名: acos
功 能: 反余弦函数
用 法: double acos(double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = acos(x);
printf("The arc cosine of %lf is %lf\n", x, result);
return 0;
}
函数名: allocmem
功 能: 分配DOS存储
用 法: int allocmem(unsigned size, unsigned *seg);
程序例:
#include <dos.h>
#include <alloc.h>
#include <stdio.h> int main(void)
{
unsigned int size, segp;
int stat; size = 64; /* (64 x 16) = 1024 bytes */
stat = allocmem(size, &segp);
if (stat == -1)
printf("Allocated memory at segment: %x\n", segp);
else
printf("Failed: maximum number of paragraphs available is %u\n",
stat); return 0;
}
函数名: arc
功 能: 画一弧线
用 法: void far arc(int x, int y, int stangle, int endangle, int radius);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h> int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 45, endangle = 135;
int radius = 100; /* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); /* read result of initialization */
errorcode = graphresult(); /* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch(); exit(1); /* terminate with an error code */
} midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor()); /* draw arc */
arc(midx, midy, stangle, endangle, radius); /* clean up */
getch();
closegraph();
return 0;
}
函数名: asctime
功 能: 转换日期和时间为ASCII码
用 法: char *asctime(const struct tm *tblock);
程序例:
#include <stdio.h>
#include <string.h>
#include <time.h> int main(void)
{
struct tm t;
char str[80]; /* sample loading of tm structure */ t.tm_sec = 1; /* Seconds */
t.tm_min = 30; /* Minutes */
t.tm_hour = 9; /* Hour */
t.tm_mday = 22; /* Day of the Month */
t.tm_mon = 11; /* Month */
t.tm_year = 56; /* Year - does not include century */
t.tm_wday = 4; /* Day of the week */
t.tm_yday = 0; /* Does not show in asctime */
t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */ /* converts structure to null terminated
string */ strcpy(str, asctime(&t));
printf("%s\n", str); return 0;
}
函数名: asin
功 能: 反正弦函数
用 法: double asin(double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = asin(x);
printf("The arc sin of %lf is %lf\n", x, result);
return(0);
}
函数名: assert
功 能: 测试一个条件并可能使程序终止
用 法: void assert(int test);
程序例:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h> struct ITEM {
int key;
int value;
}; /* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
assert(itemptr != NULL);
/* add item to list */
} int main(void)
{
additem(NULL);
return 0;
}
函数名: atan
功 能: 反正切函数
用 法: double atan(double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = atan(x);
printf("The arc tangent of %lf is %lf\n", x, result);
return(0);
}
函数名: atan2
功 能: 计算Y/X的反正切值
用 法: double atan2(double y, double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 90.0, y = 45.0; result = atan2(y, x);
printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);
return 0;
}
函数名: atexit
功 能: 注册终止函数
用 法: int atexit(atexit_t func);
程序例:
#include <stdio.h>
#include <stdlib.h> void exit_fn1(void)
{
printf("Exit function #1 called\n");
} void exit_fn2(void)
{
printf("Exit function #2 called\n");
} int main(void)
{
/* post exit function #1 */
atexit(exit_fn1);
/* post exit function #2 */
atexit(exit_fn2);
return 0;
}
函数名: atof
功 能: 把字符串转换成浮点数
用 法: double atof(const char *nptr);
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
float f;
char *str = "12345.67"; f = atof(str);
printf("string = %s float = %f\n", str, f);
return 0;
}
函数名: atoi
功 能: 把字符串转换成长整型数
用 法: int atoi(const char *nptr);
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
int n;
char *str = "12345.67"; n = atoi(str);
printf("string = %s integer = %d\n", str, n);
return 0;
}
函数名: atol
功 能: 把字符串转换成长整型数
用 法: long atol(const char *nptr);
程序例: #include <stdlib.h>
#include <stdio.h> int main(void)
{
long l;
char *str = "98765432"; l = atol(lstr);
printf("string = %s integer = %ld\n", str, l);
return(0);
}