×öµ½×¨Òµ£¬Ó¦¸ÃÊÇÿ¸öÖ°Òµ³ÌÐòÔ±Ó¦¸ÃÒªÇó×Ô¼º×öµ½µÄ¡£
ÈÃÎÒÃÇ¿´¿´lua
ÊÇ
ÔõôдͷÎļþµÄ¡£
1.License Agreement
License
Agreement
Ó¦¸Ã¼ÓÔÚÿ¸öÍ·ÎļþµÄ¶¥²¿¡£
Lua Sample:
/*
** $Id: lua.h,v 1.175b 2003/03/18 12:31:39 roberto Exp $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
**
http://www.lua.org
mailto:info@lua.org
** See Copyright Notice at the end of this file
*/
2.guard define
Õû¸öÍ·ÎļþÓ¦¸ÃÔÚguard
define
Ö®¼ä
#ifndef lua_h
#define
lua_h
#endif
ÁíÍ⣬Èç¹ûÕâ¸öÍ·Îļþ¿ÉÄܸø
c++
ʹÓã¬Òª¼ÓÉÏ
#ifdef __cplusplus
extern
"
C
"
{
#endif
/*
The lines within extern "C"
*/
#ifdef __cplusplus
}
#endif
3.
¾¡Á¿²»ÒªÔÚÍ·ÎļþÖб©Â¶Êý¾Ý½á¹¹
Õ ......
http://west263.com/info/html/chengxusheji/C-C--/20080224/9240.html
1. gcnew·µ»ØµÄÊǸö¾ä±ú(Handle)£¬¶ønew·µ»ØµÄÊÇʵ¼ÊµÄÄÚ´æµØÖ·.
¡¡¡¡2. gcnew´´½¨µÄ¶ÔÏóÓÉÐéÄâ»úÍйܣ¬¶ønew´´½¨µÄ¶ÔÏó±ØÐë×Ô¼ºÀ´¹ÜÀíºÍÊÍ·Å.
¡¡¡¡µ±È»£¬´Ó³ÌʽԱµÄ½Ç¶ÈÀ´Ëµ£¬¹ÜËûÊǾä±ú»¹ÊÇʲôÆäËûµÄ¶«Î÷£¬×ÜÅܲ»µôÊǶÔij¿éÄÚ´æµØÖ·µÄÒýÓã¬Êµ¼ÊÉÏÎÒÃǶ¼Äܹ»Àí½â³ÉÖ¸Õë.ÏÂÃæÎÒÃǾÍдһ¶Î´úÂëÀ´²âÊÔһϺÃÁË.
using namespace System;
ref class Foo
{
public:
Foo()
{
System::Console::WriteLine("Foo::Foo");
}
~Foo()
{
System::Console::WriteLine("Foo::~Foo");
}
public:
int m_iValue;
};
int _tmain()
{
int* pInt = new int;
int^ rInt = gcnew int;
Foo^ rFoo = gcnew Foo;
delete rFoo;
delete rInt;
delete pInt;
}
Ìرð×¢Ò⣺±¾Õ¾ËùÓÐתÔØÎÄÕÂÑÔÂÛ²»´ú±í±¾Õ¾¹Ûµã£¬±¾Õ¾ËùÌṩµÄÉãÓ°ÕÕƬ£¬²å»£¬Éè¼Æ×÷Æ·£¬ÈçÐèʹÓã¬ÇëÓëÔ×÷ÕßÁªÏµ
¡¡¡¡ÎҰѵ÷ÊÔµÄʱºòJIT±àÒëµÄ»ã±à´úÂëÔñ¼Á˲¿·ÖÈçÏÂÏÔʾ£¨Çë×¢ÒâºìÉ«²¿·Ö£©£º
int* pInt = new int;
0000004c mov ecx£¬4
00000051 call dword ptr ds:[03B51554h]
00000057 mov esi£¬eax
00000059 mov dword pt ......
1 . ÓÃÔ¤´¦ÀíÖ¸Áî#define ÉùÃ÷Ò»¸ö³£Êý£¬ÓÃÒÔ±íÃ÷1ÄêÖÐÓжàÉÙÃ루ºöÂÔÈòÄêÎÊÌ⣩
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
ÎÒÔÚÕâÏë¿´µ½¼¸¼þÊÂÇ飺
1) #define Óï·¨µÄ»ù±¾ÖªÊ¶£¨ÀýÈ磺²»ÄÜÒԷֺŽáÊø£¬À¨ºÅµÄʹÓ㬵ȵȣ©
2)¶®µÃÔ¤´¦ÀíÆ÷½«ÎªÄã¼ÆËã³£Êý±í´ïʽµÄÖµ£¬Òò´Ë£¬Ö±½Óд³öÄãÊÇÈçºÎ¼ÆËãÒ»ÄêÖÐÓжàÉÙÃë¶ø²»ÊǼÆËã³öʵ¼ÊµÄÖµ£¬ÊǸüÇåÎú¶øûÓдú¼ÛµÄ¡£
3) Òâʶµ½Õâ¸ö±í´ïʽ½«Ê¹Ò»¸ö16λ»úµÄÕûÐÍÊýÒç³ö-Òò´ËÒªÓõ½³¤ÕûÐÍ·ûºÅL,¸æËß±àÒëÆ÷Õâ¸ö³£ÊýÊǵij¤ÕûÐÍÊý¡£
4) Èç¹ûÄãÔÚÄãµÄ±í´ïʽÖÐÓõ½UL£¨±íʾÎÞ·ûºÅ³¤ÕûÐÍ£©£¬ÄÇôÄãÓÐÁËÒ»¸öºÃµÄÆðµã¡£¼Çס£¬µÚÒ»Ó¡ÏóºÜÖØÒª¡£
2 . дһ¸ö"±ê×¼"ºêMIN £¬Õâ¸öºêÊäÈëÁ½¸ö²ÎÊý²¢·µ»Ø½ÏСµÄÒ»¸ö¡£
#define MIN(A,B) £¨£¨A£© <= (B) ? (A) : (B))
Õâ¸ö²âÊÔÊÇΪÏÂÃæµÄÄ¿µÄ¶øÉèµÄ£º
1) ±êʶ#defineÔÚºêÖÐÓ¦ÓõĻù±¾ÖªÊ¶¡£ÕâÊǺÜÖØÒªµÄ¡£ÒòΪÔÚ Ç¶Èë(inline)²Ù×÷·û ±äΪ±ê×¼CµÄÒ»²¿·Ö֮ǰ£¬ºêÊÇ·½±ã²úÉúǶÈë´úÂëµÄΨһ·½·¨£¬¶ÔÓÚǶÈëʽϵͳÀ´Ëµ£¬ÎªÁËÄÜ´ïµ½ÒªÇóµÄÐÔÄÜ£¬Ç¶Èë´úÂë¾³£ÊDZØÐëµÄ·½·¨¡£
2 ......
×Ö·û´®ÊÇCÓïÑԵľ«»ªÖ®Ò»£¬CÓïÑÔÊDZÊÊÔ¿¼ÌâµÄºËÐÄ֪ʶµã£¬²»¹ÜÄãÊÇѧc++£¬Ñ§java»¹ÊÇc#¡¢.net£¬»¹Êǽű¾Ê²Ã´µÄ£¬×îºÃ»¹ÊǶ®µãC°É£¬²»¶®C±ÊÊÔ»òÐí±È½Ï³Ô¿÷¡£ËùÒÔÔÚ±ÊÊÔÃæÊÔÖУ¬×Ö·û´®µÄÎÊÌâÊǾ³£³öÏֵģ¬ÆäÖÐÓÐÒ»ÀàÎÊÌâ¾ÍÊÇ×Ô¼ºÊµÏÖһЩ»ù±¾µÄC±ê×¼¿âµÄ×Ö·û´®´¦Àíº¯Êý»òÆäËûC±ê×¼¿âº¯Êý¡£
ÎÊÌâÒ»ÃèÊö£º Óñê×¼Cдһ¸öÅжϸø¶¨×Ö·û´®³¤¶ÈµÄº¯Êý¡£ÒªÇ󣺲»¿ÉʹÓÿ⺯Êý£¬×Ö·û´®ÓÃchar *c´«È룬¿ÉÓÃα´úÂ룬µ«ÊÇ·ÖÊý¼õ°ë¡£
·ÖÎö£ºÌâÄ¿ºÜÃ÷È·£¨×Ô¼ºÊµÏÖstrlenµÄ¹¦ÄÜ£©£¬Ò²²»ÄÑ£¬Ö÷ÒªÊÇ¿¼²ìC×Ö·û´®»ù±¾¹¦£¬Ò»°ãÈ˶¼Ó¦¸ÃÄÜдºÃ¡£Ö±½Ó¸ø´úÂ룺
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int strlength(const char* str)
{
int i=0;
while(*str!=0)
{
i++;
str++;
}
return i;
}
int main()
{
const char* test="abcdef";
printf("²âÊÔ×Ö·û´®³¤¶ÈΪ:%d\n",strlen(test));
return 0;
}
ÎÊÌâ¶þ£º°Ñ¸ø¶¨×Ö·û´®ÖеÄСд×Öĸת»¯Îª¶ÔÓ¦µÄ´óд×ÖĸÊä³ö¡£
·ÖÎö£ºÌâÄ¿ÒÀ¾É¼òµ¥£¬Ö±½Ó¸ø´úÂ룺
#include <stdio.h>
void convert(char *str)
{
while(*str!=0)
{
if(*str>='a'&&*str& ......
µ±Õâ¸öÊÀ½ç»¹Ö»ÓÐCµÄʱºò£¬ÊDz»ÐèÒªextern "C"µÄ¡£
µ«ÊÇ£¬µ±C++³öÏÖÖ®ºó£¬ÓÐʱºò£¬ÎÒÃǾÍÐèÒªextern "C"ÁË¡£
ÄǾ¿¾¹ÊÇÔÚʲôÑùµÄÇé¿öÏ£¬ÎÒÃÇÐèÒªÓÃextern "C"ÄØ£¿
ÓÐÈË˵£¬ÊÇΪÁËCÄܹ»µ÷ÓÃC++£¬ÓÐÈË˵ÊÇΪÁËÔÚC++ÖÐÄܵ÷ÓÃCµÄ¿âº¯Êý¡£ÊDz»ÊÇ°ÑÄãŪºýÍ¿ÁË£¿
ÏÈ˵˵extern "C"ÊÇɶ×÷Óðɡ£
extern "C" ÊǸæËßC++±àÒëÆ÷£¬Õâ¸öº¯ÊýÊÇÍêÈ«¼æÈÝCµÄ£¬²»°üº¬C++ÓжøCÖÐûÓеÄÌØÐԵġ£²¢ÇÒ¸æËß±àÒëÆ÷£¬ÔÚÉú³ÉÄ¿±êÎļþµÄʱºò£¬Ê¹ÓÃCµÄ·½Ê½Éú³Éº¯ÊýÃû¡£
ÉÏÃæÕâ¾ä»°ÓÐÁ½¸öÖص㣬
µÚÒ»ÊÇ extern "C" Ö»ÓÐ C++±àÒëÆ÷Èϵã¬C±àÒëÆ÷ÊDz»ÈÏʶµÄ¡£
µÚ¶þÊÇ ÓÃCµÄ·½Ê½Éú³Éº¯ÊýÃû¡£Ê²Ã´½Ð "ÓÃCµÄ·½Ê½Éú³Éº¯ÊýÃû"£¿ C++±àÒëÆ÷ºÍC±àÒëÆ÷Éú³Éº¯ÊýÃûµÄ·½Ê½ÊDz»Í¬µÄ¡£ÒòΪC++ÒªÖ§³Öº¯ÊýÖØÔØ£¬ËùÒÔC++±àÒëÆ÷ÔÚÉú³Éº¯ÊýÃûµÄʱºò»á°Ñº¯Êý²ÎÊýµÄÀàÐͼÓÔÚº¯ÊýÃûÖС£¶øC±àÒëÆ÷¾Í±È½Ï¼òµ¥£¬Ö±½ÓÔÚº¯ÊýÃû×ÖÇ°¼ÓÒ»¸öÏ»®Ï߸㶨¡£
±ÈÈç void foo( int x ); ÕâÑùµÄº¯Êý
C±àÒëÆ÷±àÒë³öÀ´ÔÚ·ûºÅ¿âÖеÄÃû×ÖÊÇ_foo£¬¶øC++±àÒëÆ÷±àÒë³öÀ´ÔÚ·ûºÅ¿âÖеÄÃû×Ö¿ÉÄÜÊÇ _foo_int ÕâÑùµÄ¡£
ÄÇôʹÓà extern "C" ÓÐʲôÒâÒåÄØ£¿
ÎÒ¾õµÃ ”ΪÁËC++ÖÐÄܵ÷ÓÃCµÄ¿âº¯Êý“ ÕâÑùµÄ˵·¨ÊÇÕýÈ·µÄ¡£
Ϊʲô£¿
¿¼ÂÇÏ ......
enumÀàÐ͵ijÉÔ±£¬Ä¬ÈÏÇé¿öÏÂÊÇ´Ó0¿ªÊ¼¸³Öµ£»
Èç¹ûÖмäij¸ö³ÉÔ±½øÐÐÁËÊÖ¶¯¸³ÖµµÄ»°£¬¸Ã³ÉÔ±µÄÏÂÒ»¸ö³ÉÔ±µÄֵΪ¸Ã³ÉÔ±µÄÖµ+1
#include <stdio.h>
typedef enum {
PLAYMODE = 1, // ĬÈÏ´Ó0¿ªÊ¼
PAUSEMODE,
STOPMODE = 5,
TRACKRPTMODE,
MIXMODE
}Status_t;
int main()
{
int n = 4;
switch(n)
{
case PLAYMODE:
printf("Hello\n");
break;
case PAUSEMODE:
printf("ccc\n");
break;
case MIXMODE:
printf("MIXMODE is ...");
break;
default:
break;
}
getchar();
return 0;
}
³ÌÐòÔÚVC2005ϱàÒëͨ¹ý£¬Ô´ÂëÀ´Ô´ÓÚÍøÂç ......