Board logo

標題: 開始撰寫C++程式的問題 [打印本頁]

作者: 花之慶次    時間: 2007-3-19 00:05     標題: 開始撰寫C++程式的問題

想請問一下interpreter與compiler有何不同, 兩者之間有何優點和缺點, 以及portability是什麼意思??
作者: jayzhou_2046    時間: 2007-3-19 11:19

引用:
原帖由 花之慶次 於 2007-3-19 00:05 發表
想請問一下interpreter與compiler有何不同, 兩者之間有何優點和缺點, 以及portability是什麼意思??
compiler(假定已和linker結合了)把源代碼編譯為機器碼(machine code)或虛擬機器(virtual machine)的位元碼(byte code), 可以直接在機器運行. 如C/C++, Java.
interpreter則把源代碼實時在機器上執行.  如perl, python.
如不討論虛擬機器, compiler生成的機器碼的運行速度比較interpreter實時執行快.

portability- 指把已開發應用程式, 由一個作業系統平台改成可在另一個平台運行的可能性; 又或指把用某一個編程語言開發的應用程式, 由一個編譯器改成可在另一個編譯器成功編譯的可能性.
作者: b4321    時間: 2007-3-19 14:55

Complier will turn your high level code into machine code, which can be runned much faster.

Intepreter will only read your high level codes (eg scripts) line by line and execute the order, which is much slower.
作者: 花之慶次    時間: 2007-3-19 23:42

然則, 又如何定義有關ANSI/ISO C++的標準??
作者: jayzhou_2046    時間: 2007-3-20 08:49

引用:
原帖由 花之慶次 於 2007-3-19 23:42 發表
然則, 又如何定義有關ANSI/ISO C++的標準??
閣下可以購買以下文本,
自會清楚:
http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS%2FISO%2FIEC+14882%2D2003&source=google&adgroup=c++&keyword=c%2B%2B%20standards&gclid=CLv8_uSRgosCFRCObgodmnnTKQ
作者: 花之慶次    時間: 2007-3-20 23:58

在C++中, 如何去分辨出何謂語法錯誤(syntax error), 何謂語意錯誤(semantic error)??
作者: sam0621    時間: 2007-4-2 23:24

Syntax error occurs when you write code in a manner not allowed by the rules of the language. It can be identified by the compiler.

Semantic error occurs when the syntax of your code is correct, but the semantics or meaning are not what you intended. It can only be identified when you run the program (after compilation).

The above definitions apply to not only C++, but also the other programming languages.
作者: 花之慶次    時間: 2007-4-3 00:18

如果我想將n1, n2宣告成整數型態變數, 宣告完成以後, 再將n1設值為6, n2設值為8, 最後將n1, n2的值印出, 而我所撰寫的程式究竟出了什麼問題??
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
    int n1, n2;
    char ch;
    n1=6;
    n2=8;
    ch='w';
    cout << "n1" << + << "n2" << = << n1+n2= << endl;
    system("pause");
    return 0;
}

最主要的是出了什麼問題!!
作者: jayzhou_2046    時間: 2007-4-3 09:13

cout << "n1" << + << "n2" << = << n1+n2= << endl;
這一句相信應該是這樣吧:
cout << "n1 + n2 = " << n1+n2 << endl;
作者: 花之慶次    時間: 2007-4-3 23:20

以下這程式在實際經驗有何用處以及有沒有必要背熟??
// prog3_2.cpp, 印出各種資料型態的長度
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
    //定義各種資料型態的變數
    unsigned int i=0;
    unsigned short int j=0;
    char ch=' ';
    float f=0.0f;
    double d=0.0;
   
    //印出各種資料型態的長度
    cout << "sizeof(int)=" << sizeof(int) << endl;
    cout << "sizeof(long int)=" << sizeof(long int) << endl;
    cout << "sizeof(unsigned int)=" << sizeof(i) << endl;
    cout << "sizeof(short int)=" << sizeof(short int) << endl;
    cout << "sizeof(unsigned short int)=" << sizeof(j) << endl;
    cout << "sizeof(char)=" << sizeof(ch) << endl;
    cout << "sizeof(float)=" << sizeof(f) << endl;
    cout << "sizeof(double)=" << sizeof(d) << endl;
    cout << "sizeof(bool)=" << sizeof(bool) << endl;
    system("pause");
    return 0;
}
作者: 花之慶次    時間: 2007-4-3 23:29

這是一個整數資料型態的溢位, 究竟何謂溢位?
// prog3_3.cpp, 整數資料型態的溢位
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
    int i=2147483647;       // 宣告i為整數, 並設值為2147483647
   
     cout << "i=" << i << endl;  // 印出i 的值
     cout << "i+1=" << i+1 << endl;  // 印出i+1的值
     cout << "i+2=" << i+2 << endl;  // 印出i+2的值
     system("pause");
     return 0;
}
作者: 花之慶次    時間: 2007-4-3 23:41

如果以ASCII碼中, 英語小寫a-z是不是代表不同的數字?? 以h為例, 是不是就是以104來作為代表??
同時, 有關二進位, 十進位的轉換是如何計算的呢??

[ 本帖最後由 花之慶次 於 2007-4-3 23:55 編輯 ]
作者: melvillo    時間: 2007-4-27 14:33

引用:
原帖由 jayzhou_2046 於 2007-3-19 11:19 發表

compiler(假定已和linker結合了)把源代碼編譯為機器碼(machine code)或虛擬機器(virtual machine)的位元碼(byte code), 可以直接在機器運行. 如C/C++, Java.
interpreter則把源代碼實時在機器上執行.  如perl, ...
就是这个理~
作者: 花之慶次    時間: 2007-5-5 00:08

有些奇怪

// prog1_1.cpp.cpp : 定義主控台應用程式的進入點。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{
        cout << "Hello!!我是陳大文, 你好" << endl;
        system("pause");
        return 0;
}

執行如下:
'prog1_1.cpp.exe': 已載入 'C:\Documents and Settings\Mau hung Li\My Documents\Visual Studio 2005\Projects\prog1_1.cpp\Debug\prog1_1.cpp.exe',已載入符號
'prog1_1.cpp.exe': 已載入 'C:\WINDOWS\system32\ntdll.dll',未載入符號
'prog1_1.cpp.exe': 已載入 'C:\WINDOWS\system32\kernel32.dll',未載入符號
偵錯工具:: 處理序載入期間,發生未處理的非持續性 STATUS_DLL_NOT_FOUND 例外狀況
'[284] prog1_1.cpp.exe: 原生' 程式以返回碼 -1073741515 (0xc0000135) 結束。


為什麼會這樣??




歡迎光臨 香港 Xocat Forum 討論區 (http://p.xocat.com/p/) Powered by Discuz! 6.0.0