[其他]关于C语⾔中使⽤未声明函数的问题
在c语⾔中,碰到⼀个.c⽂件,⽆.h头⽂件,在另⼀.c⽂件调⽤函数时,并没有进⾏声明extern,
此时编译器不会报错,会默认去查同名的函数,这样会存在⼀些问题,查了些资料,稍微总结了下:
总结:
1.声明函数可以不加extern,函数默认extern。
2.声明变量必须要加extern.
3.如果不加extern,编译器会默认去查同函数名的函数,但会出错。
  1).参数中如果出现float,⼀定会出现读取错误,但编译运⾏不报错.如果形参float后有int*类型的变量,编译运⾏会报错,之前有则不会报错。
  2).函数形参如果都是整数类型的值(char、short、int、long、long long等),都可以正常传值,值的⼤⼩可以⼤于int范围
  3).函数返回值⽆所谓什么类型,但⼤⼩范围不能超过int型范围(-2147483648 ~ +2147483647),超过
会返回值错误.
    可以理解为:默认返回值为int,后被强转成需要返回的类型(long、float等).
main.c
#include<stdio.h>
//extern int test_1(int a);
c语言编译器怎么用不了//int test_2(int a, int b);
//...
int main()
{
int a0 = 1;
int a[10] = { 0 };
int*b = a;
float c = 0.01f;
char d = 5;
long long e = 2147483648;
long long f = 2147483649;
int a1 = test_1(a0);      //3
int a2 = test_2(a0, a0 + 1);//3
float a3 = test_3(a0, a0 + 1);//3.00
float a4 = test_4(a0, c);// -85899342, c在那边读取2.000,
int a5 = test_5(a0, c); //  3, c在那边读取2.000,
int a6 = test_6(a0, c, a0 + 1);// 1065646818,  c在那边读取2.000, a0+1读为:1065646817
int a7 = test_7(a0, d); //6
int a8 = test_8(a0, b); //3, b[1]正常写⼊8
int a9 = test_9(a0, b, c);//3, c在那边读取2.000,b[1]正常写⼊10
//int a10 = test_10(a0, c, b);//报错,c读取为2.00,b报内存冲突
long long a11 = test_11(a0, e);//2147483647, e在那边正常读为2147483648,说明形参超出int读取正常
long long a12 = test_11(a0, f);//-2147483648, f在那边正常读为2147483649,说明返回值超出int会读取出错
getchar();
}
test.c
int test_1(int a)
{
return a + 2;
}
int test_2(int a, int b)
{
return a + b;
}
float test_3(int a, int b)
{
return a + b;
}
float test_4(int a, float b)
{
float c = a + b;
return c;
}
int test_5(int a, float b)
{
int c = a + b;
return c;
}
int test_6(int a, float b, int c)
{
int d = a + c;
return d;
}
int test_7(int a, char b)
{
int c = a + b;
return c;
}
int test_8(int a, int* c)
{
c[1] = 8;
return a + 2;
}
int test_9(int a, int* c, float b)
{
c[1] = 10;
return a + 2;
}
int test_10(int a, float b, int* c)
{
c[1] = 10;
return a + 2;
}
long long test_11(int a, long long b)
{
long long c =  b-1;
return c;
}
(32位系统)
char -128 ~ +127 (1 Byte)
short -32767 ~ + 32768 (2 Bytes)
unsigned short 0 ~ 65536 (2 Bytes)
int -2147483648 ~ +2147483647 (4 Bytes)
unsigned int 0 ~ 4294967295 (4 Bytes)
long == int
long long -9223372036854775808 ~ +9223372036854775807 (8 Bytes) double 1.7 * 10^308 (8 Bytes)
unsigned int 0~4294967295
long long的最⼤值:9223372036854775807
long long的最⼩值:-9223372036854775808
unsigned long long的最⼤值:1844674407370955161
__int64的最⼤值:9223372036854775807
__int64的最⼩值:-9223372036854775808
unsigned __int64的最⼤值:18446744073709551615