Ò»¸öc/c++º¯Êýµ÷ÓÃÕ»µÄʵÏÖ
º¯Êýµ÷ÓÃÕ»µÄʵÏÖ¡£¿ÉÓÃÓÚʵÏÖ¼òµ¥µÄ½Å±¾½âÊÍÆ÷¡£
ÉùÃ÷:
#pragma once
const int BUFFERSIZE = 1024;
const int growfactor = 2;
// this stack is used as call stack.
class TStack{
private:
size_t size; // the stack length
size_t pos; // the stack top position
char *buffer; // the buffer
private:
void push(void* D, size_t bytecount); // the implementation of push
void* pop(size_t bytecount); // the implementation of pop
public:
TStack(size_t _size = BUFFERSIZE, size_t _pos = 0); // initialize
TStack(const TStack& o); // copy
TStack& operator=(const TStack& o); // assignment
void pushInt(int i) { push(&i, sizeof(int)); } // push an int
void pushLong(long l) { push(&l, sizeof(long)); } // push a long
void pushfloat(double f) { push(&f, sizeof(f));} // push a double
void pushPointer(void* p){ push(p, sizeof(p)); }
// int
int popInt() { return *(int *)pop(sizeof(int));} // pop an int
long popLong() { return *(long *)pop(sizeof(long)); } // pop an int
double* popfloat() { return (double*)pop(sizeof(double)); } // pop a double
void* popPointer() { return pop(sizeof(void*)) ; }
void clear() { pos = 0; }
};
ʵÏÖ£º
#include "stdafx.h"
#include "TStack.h"
#include "new.h"
void TStack::push( void* D, size_t bytecount )
{
// if memory is not enough
// if run under multithread envionment,
// a lock or critical section should be added
if (pos + bytecount > size)
{
size_t oldsize = size;
size *= growfactor;
char *newbuffer = new char[size];
memcpy(newbuffer, buffer, oldsize);
delete buffer;
buffer = newbuffer;
}
memcpy(buffer+pos, D, bytecount);
pos += bytecount;
}
void* TStack::pop( size_t bytecount )
{
// need synchronization f
Ïà¹ØÎĵµ£º
ÏÖÔںܶàÈ˶¼ÎÊ C++ºÍJava ÄĸöºÃ. Æäʵ¼¼ÊõÉϸ÷Óи÷µÄºÃ´¦Óë²»×ã,ÎÒÏë´ó¼ÒËù˵µÄºÃ²»ºÃÖ¸µÃÊÇǰ;ºÃ²»ºÃ,׬µÄ¶à²»¶à.
Ҫ˵׬Ǯ×î¶àµÄ¿Ï¶¨ÊÇC++ÁË.ÒòΪһÃż¼ÊõÊÇ·ñֵǮȫ¿´»áËüµÄÈËÓжàÉÙ¶ø²»ÔÚÓÚÕâ¸ö¼¼Êõ±¾ÉíµÄºÃ»µ. C++Éæ¼°Ó²¼þµ×²ãµÄ¶«Î÷±È½Ï¶à,ѧÆðÀ´ºÜ¸´ÔÓ,»áµÄÈËÉÙ,ËùÒÔֵǮ.
&nb ......
Delphi Óë C/C++ Êý¾ÝÀàÐͶÔÕÕ±í
DelphiÊý¾ÝÀàÐÍC/C++
ShorInt
8λÓзûºÅÕûÊý
char
Byte
8λÎÞ·ûºÅÕûÊý
BYTE,unsigned short
SmallInt
16λÓзûºÅÕûÊý
short
Word
16λÎÞ·ûºÅÕûÊý
unsigned short
Integer,LongInt
32λÓзûºÅÕûÊý
int,long
Cardinal,LongWord/DWORD
32λÎÞ·ûºÅÕûÊý
unsigned long
Int6 ......
±àÒëµ¥¸öÔ´Îļþ
ΪÁ˽øÐвâÊÔ£¬Äã¿ÉÒÔ´´½¨“Hello World”³ÌÐò£º
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
printf(”Hello world!\n”);
exit(0);
}
ʹÓÃÈçÏÂÃüÁî±àÒë²¢²âÊÔÕâ¸ö´úÂ룺
# gcc -o hello hello.c
# ./hello
Hello wordl!
ÔÚÄ ......
CÖÐÈçºÎµ÷ÓÃC++º¯Êý?
Ç°Õó×Ó±»Îʼ°Ò»¸öÔÚCÖÐÈçºÎµ÷ÓÃC++º¯ÊýµÄÎÊÌ⣬µ±Ê±¼òµ¥»Ø´ðÊǽ«º¯ÊýÓÃextern "C"ÉùÃ÷£¬µ±±»Îʼ°ÈçºÎ½«ÀàÄÚ³ÉÔ±º¯ÊýÉùÃ÷ʱ£¬Ò»Ê±ÓïÈû£¬ºóÀ´ÍøÉϲéÁËÏ£¬ÍøÉÏÓÐÒ»·ÒëC++Ö®¸¸µÄÎÄÕ¿ÉÒÔ×÷Ϊ½â´ð£¬ËìÄÃÀ´Markһϡ£
½« C++ º¯ÊýÉùÃ÷Ϊ``extern "C"''£¨ÔÚÄãµÄ C++ ´úÂëÀï×öÕâ¸öÉùÃ÷£©£¬ ......
¡¡¡¡extern "C" °üº¬Ë«Öغ¬Ò壬´Ó×ÖÃæÉϼ´¿ÉµÃµ½£ºÊ×ÏÈ£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“extern”µÄ£»Æä´Î£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“C”µÄ¡£ÈÃÎÒÃÇÀ´Ïêϸ½â¶ÁÕâÁ½Öغ¬Òå¡£
¡¡¡¡£¨1£© ±»extern "C"ÏÞ¶¨µÄº¯Êý»ò±äÁ¿ÊÇexternÀàÐ͵ģ»
¡¡¡¡externÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿É¼ûÐÔ£©µÄ¹Ø¼ü×Ö£¬¸Ã¹ ......