2012-07-06 354 views
3

我一直堅持這個很長一段時間,由於某種原因,我的C代碼不編譯。它產生了大量CMATH錯誤C編譯時cmath錯誤

,因爲它會採取了很多的空間來把我的代碼和錯誤起來:

#include <stdlib.h> 
#include <stdio.h> 
#include <Windows.h> 
#include <fstream> 

typedef unsigned char* pointer; 

void printDbPointers(void); 
void show_int(int); 
void show_bytes(unsigned char*, int); 
void floatingPointRep(); 
void fahrenheit(); 

int main() 
{ 
    int a = 100; 
    show_int(a); 
    floatingPointRep(); 
    fahrenheit(); 
    printDbPointers(); 
    Sleep(100000); 
    return 0; 
} 

void printDbPointers(){ 
    char hi[7] = {'t', 'i', 'g', 'e', 'r', '\0'}; 
    char *p, **dp; 

    p = &(hi[0]); 
    dp = &p; 

    printf("%c %c\n", *p, **dp); 
    printf("%p %p %p\n", p, *dp, hi); 
    p+=1; 
    printf("%c, %c\n", *p, **dp); 
    printf("%p %p %p\n", p, *dp, hi); 
    *dp+=2; 
    printf("%c, %c\n", *p, **dp); 
    printf("%p %p %p\n", p, *dp, hi); 
} 


void show_int(int x) 
{ 
    show_bytes((pointer) &x, sizeof(int)); 
} 

void show_bytes(pointer start, int len) 
{ 
    int i; 
    for(i=0;i<len;i++) 
    { 
     // printf("0x%p\t0x%.2x\n", start + i, start[i]); 
     printf("0x%p\t\n", start + i, start[i]); 
     printf("\n"); 
    } 
} 


void floatingPointRep() 
{ 
    float f1 = 1.0; 
    float f2 = 0.0; 
    int i; 
    for (i=0; i<10; i++) { 
     f2 += 1.0/10.0; 
    } 

    printf("0x%08x 0x%08x\n", *(int*)&f1, *(int*)&f2); 
    printf("f1 = %10.8f\n", f1); 
    printf("f2 = %10.8f\n\n", f2); 

    f1 = 1E30; 
    f2 = 1E-30; 
} 

void fahrenheit() 
{ 
    int i; 
    double arr[3] = {12345678.000, 98765345.333, 456793332.300}; 
    for (i = 0; i < 3; i++) 
    printf ("%g\n", arr[i]); 
} 

但是,如果它違反了這樣的規則把問題代碼別的地方,讓我知道,我會把它放在這裏

 73 error C1003: error count exceeds 100; stopping compilation 
4 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 28 1 
7 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 29 1 
11 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 30 1 
15 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 31 1 
19 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 32 1 
23 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 33 1 
27 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 34 1 
31 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 35 1 
34 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 37 1 
37 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 38 1 
41 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 39 1 
45 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 40 1 
49 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 41 1 
53 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 42 1 
57 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 43 1 
61 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 44 1 
64 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 46 1 
66 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 48 1 
69 error C2059: syntax error : ';' c:\program files\microsoft visual studio 11.0\vc\include\cmath 49 1 
63 error C2061: syntax error : identifier 'abs' c:\program files\microsoft visual studio 11.0\vc\include\cmath 46 1 
65 error C2061: syntax error : identifier 'acos' c:\program files\microsoft visual studio 11.0\vc\include\cmath 48 1 
3 error C2061: syntax error : identifier 'acosf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 28 1 
33 error C2061: syntax error : identifier 'acosl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 37 1 
67 error C2061: syntax error : identifier 'asin' c:\program files\microsoft visual studio 11.0\vc\include\cmath 48 1 
5 error C2061: syntax error : identifier 'asinf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 28 1 
35 error C2061: syntax error : identifier 'asinl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 37 1 
68 error C2061: syntax error : identifier 'atan' c:\program files\microsoft visual studio 11.0\vc\include\cmath 49 1 
70 error C2061: syntax error : identifier 'atan2' c:\program files\microsoft visual studio 11.0\vc\include\cmath 49 1 
8 error C2061: syntax error : identifier 'atan2f' c:\program files\microsoft visual studio 11.0\vc\include\cmath 29 1 
38 error C2061: syntax error : identifier 'atan2l' c:\program files\microsoft visual studio 11.0\vc\include\cmath 38 1 
6 error C2061: syntax error : identifier 'atanf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 29 1 
36 error C2061: syntax error : identifier 'atanl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 38 1 
71 error C2061: syntax error : identifier 'ceil' c:\program files\microsoft visual studio 11.0\vc\include\cmath 49 1 
9 error C2061: syntax error : identifier 'ceilf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 29 1 
39 error C2061: syntax error : identifier 'ceill' c:\program files\microsoft visual studio 11.0\vc\include\cmath 38 1 
72 error C2061: syntax error : identifier 'cos' c:\program files\microsoft visual studio 11.0\vc\include\cmath 50 1 
10 error C2061: syntax error : identifier 'cosf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 30 1 
12 error C2061: syntax error : identifier 'coshf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 30 1 
42 error C2061: syntax error : identifier 'coshl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 39 1 
40 error C2061: syntax error : identifier 'cosl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 39 1 
13 error C2061: syntax error : identifier 'expf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 30 1 
43 error C2061: syntax error : identifier 'expl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 39 1 
14 error C2061: syntax error : identifier 'fabsf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 31 1 
44 error C2061: syntax error : identifier 'fabsl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 40 1 
16 error C2061: syntax error : identifier 'floorf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 31 1 
46 error C2061: syntax error : identifier 'floorl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 40 1 
17 error C2061: syntax error : identifier 'fmodf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 31 1 
47 error C2061: syntax error : identifier 'fmodl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 40 1 
18 error C2061: syntax error : identifier 'frexpf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 32 1 
48 error C2061: syntax error : identifier 'frexpl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 41 1 
20 error C2061: syntax error : identifier 'ldexpf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 32 1 
50 error C2061: syntax error : identifier 'ldexpl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 41 1 
22 error C2061: syntax error : identifier 'log10f' c:\program files\microsoft visual studio 11.0\vc\include\cmath 33 1 
52 error C2061: syntax error : identifier 'log10l' c:\program files\microsoft visual studio 11.0\vc\include\cmath 42 1 
21 error C2061: syntax error : identifier 'logf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 32 1 
51 error C2061: syntax error : identifier 'logl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 41 1 
24 error C2061: syntax error : identifier 'modff' c:\program files\microsoft visual studio 11.0\vc\include\cmath 33 1 
54 error C2061: syntax error : identifier 'modfl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 42 1 
25 error C2061: syntax error : identifier 'powf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 33 1 
55 error C2061: syntax error : identifier 'powl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 42 1 
26 error C2061: syntax error : identifier 'sinf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 34 1 
28 error C2061: syntax error : identifier 'sinhf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 34 1 
58 error C2061: syntax error : identifier 'sinhl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 43 1 
56 error C2061: syntax error : identifier 'sinl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 43 1 
29 error C2061: syntax error : identifier 'sqrtf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 34 1 
59 error C2061: syntax error : identifier 'sqrtl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 43 1 
30 error C2061: syntax error : identifier 'tanf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 35 1 
32 error C2061: syntax error : identifier 'tanhf' c:\program files\microsoft visual studio 11.0\vc\include\cmath 35 1 
62 error C2061: syntax error : identifier 'tanhl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 44 1 
60 error C2061: syntax error : identifier 'tanl' c:\program files\microsoft visual studio 11.0\vc\include\cmath 44 1 
+0

你有#included math.h嗎? – 2012-07-06 18:28:59

+0

根本不是。這是這裏的奧祕。看到我上面的代碼鏈接。 – jmishra 2012-07-06 18:29:24

+7

似乎有些混亂。你有#include fstream,但這是C++的一部分,不是C. – 2012-07-06 18:31:10

回答

6

似乎有一些混淆。你有#included fstream,這是C++的一部分,而不是C.

似乎fstream由於某種原因自己做了#include cmath,而這些錯誤可能來自C和C++之間的不兼容。

編輯:

是,之後#包括幾個層次,CMATH被執行#included,並且CMATH不僅僅是math.h中的副本,但包含了C++ - 特定代碼。