「C言語/C++/const」の編集履歴(バックアップ)一覧はこちら

C言語/C++/const - (2012/09/10 (月) 22:19:36) の1つ前との変更点

追加された行は緑色になります。

削除された行は赤色になります。

|開発環境|Microsoft Visual C++ 2010 Express (SP1)| |実行環境|Microsoft Windows XP Home Edition (SP3)| |プロジェクトの種類|Win32 コンソール アプリケーション| |プロジェクト名|const| |アプリケーションの種類|コンソール アプリケーション| |追加のオプション|空のプロジェクト| Windowsで使われる文字(列)の型 |型名|定義|型名の元となったと思われるもの| |CHAR|char|Character| |WCHAR|wchar_t|Wide Character| |TCHAR|CHAR / WCHAR|Text Character| |LPSTR|CHAR *|Long Pointer String| |LPWSTR|WCHAR *|Long Pointer Wide character String| |LPTSTR|LPSTR / LPWSTR|Long Pointer TCHAR String| |LPCSTR|const CHAR *|Long Pointer Constant String| |LPCWSTR|const WCHAR *|Long Pointer Constant Wide character String| |LPCTSTR|LPCSTR / LPCWSTR|Long Pointer Constant TCHAR String| 参考 [[What are TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR (etc.)?>http://www.codeproject.com/Articles/76252/What-are-TCHAR-WCHAR-LPSTR-LPWSTR-LPCTSTR-etc]] ---- const.c #highlight(c){{ #include <stdio.h> // 受け取った文字列の内容を変更する可能性がある void sub1(char *p) { // *p = 'H'; // コンパイルは通るが、文字列定数への代入で実行時にエラー while (*p) { putchar(*p++); } } // 受け取った文字列の内容を変更しないことを保証する void sub2(const char *p) { // *p = 'H'; // error C2166: 左辺値は const オブジェクトに指定されています。 while (*p) { putchar(*p++); } } // ほとんど見かけないが、受け取ったポインタ変数の値を変えたくない場合に使う void sub3(const char * const p) { int i = 0; while (p[i]) { putchar(p[i++]); } } int main() { sub1("hello, world\n"); sub2("hello, world\n"); sub3("hello, world\n"); return 0; } }}
|開発環境|Microsoft Visual C++ 2010 Express (SP1)| |実行環境|Microsoft Windows XP Home Edition (SP3)| |プロジェクトの種類|Win32 コンソール アプリケーション| |プロジェクト名|const| |アプリケーションの種類|コンソール アプリケーション| |追加のオプション|空のプロジェクト| const.c #highlight(c){{ #include <stdio.h> // 受け取った文字列の内容を変更する可能性がある void sub1(char *p) { // *p = 'H'; // コンパイルは通るが、文字列定数への代入で実行時にエラー while (*p) { putchar(*p++); } } // 受け取った文字列の内容を変更しないことを保証する void sub2(const char *p) { // *p = 'H'; // error C2166: 左辺値は const オブジェクトに指定されています。 while (*p) { putchar(*p++); } } // ほとんど見かけないが、受け取ったポインタ変数の値を変えたくない場合に使う void sub3(const char * const p) { int i = 0; while (p[i]) { putchar(p[i++]); } } int main() { sub1("hello, world\n"); sub2("hello, world\n"); sub3("hello, world\n"); return 0; } }}

表示オプション

横に並べて表示:
変化行の前後のみ表示: