user-0 提问: 关于limit头文件相关问题。

回复:
user: user-1
content: 引用 2 楼 z245821190 的回复:那你能说说什么时候才用limits头文件里的值吗 使用grep（linux）或findstr（windows）命令搜索crt\src\目录下的所有文件，看哪些包含字符串"limits.h"

user: user-0
content: 那你能说说什么时候才用limits头文件里的值吗

user: user-2
content: #include <stdio.h> #include <limits.h>  #define min(x,y) ((x)<(y)?(x):(y))  int mindistance(int a[], int b[],int m,int n) {     int minimum = INT_MAX;     int x = 0, y = 0;     while (x < m && y < n) {         if (a[x] >= b[y]) {             minimum=min(minimum, a[x]-b[y]);             y++;         } else {             minimum=min(minimum,b[y]-a[x]);             x++;         }     }     return minimum; } int main() {     int a[6] = {8,18,28,38,48,49};     int b[6] = {7,15,16,17,18,56};     int m, n;      m = n =6;     printf("%d\n", mindistance(a, b, m, n));     return 0; } 头文件名写错了，include应该是limits.h； int m = n =6; 这样定义，n是未定义的，改一下；如上的代码，注意下代码风格～

user: user-1
content: 引用 3 楼 zhao4zhong1 的回复:[quote=引用 2 楼 z245821190 的回复:] 那你能说说什么时候才用limits头文件里的值吗 使用grep（linux）或findstr（windows）命令搜索crt\src\目录下的所有文件，看哪些包含字符串"limits.h"[/quote] C:\Program Files\Microsoft Visual Studio 8\VC\crt\src>grep -0is limits.h *.c *.cpp File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\assert.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\dbgheap.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\dbghook.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\dospawn.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\fread.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\gets.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\initctyp.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\initmon.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\lcnvinit.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\lconv.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\localtim.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\loctim64.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\makepath.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\mbrtowc.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\mbsnbcol.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\mbsncoll.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\mbsnicol.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\mlock.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\output.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\putch.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\putwch.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\rotl.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\rotr.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\sbheap.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\setenv.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\setvbuf.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\sprintf.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\stdargv.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\strlwr.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\strncoll.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\strnicol.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\strtol.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\strtoq.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\strupr.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\strxfrm.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\swprintf.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\vsprintf.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\vswprint.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wcrtomb.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wcsncoll.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wcsnicol.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wcstol.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wcstombs.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wcstoq.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wcsxfrm.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wctomb.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wild.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wperror.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xmbtowc.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xstol.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xstoll.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xstoul.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xstoull.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xstrxfrm.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xtoa.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xwcsxfrm.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\xwctomb.c File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\swprintn.cpp File: C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\vswprinn.cpp

user: user-3
content: http://en.cppreference.com/w/cpp/header/limits

user: user-0
content: [quote=引用 1 楼 cfjtaishan 的回复:] [我把头文件改了，不报错，但是输出结果也不对呀~结果应该是1，现在是0，还有哪里有问题吗？

user: user-4
content: 引用 2 楼 z245821190 的回复:那你能说说什么时候才用limits头文件里的值吗 这个问题问的很没意义，当然是你需要用的时候用啊 http://www.yiibai.com/c_standard_library/limits_h.html

user: user-2
content: 引用 2 楼 z245821190 的回复:那你能说说什么时候才用limits头文件里的值吗 一般是用到某个类型的最大值或者最小值时会用到吧，尤其是在嵌入式平台，由于其会设计不同的硬件平台，不同的编译器会对不同类型的数据大小做一些限制； 建议看一下limits.h里的内容，根据内容来区分在什么场合下使用。