易截截图软件、单文件、免安装、纯绿色、仅160KB

一个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


相关文档:

VB/C++/C#串口通讯源代码【附详细注释】


VB
    If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
    MSComm1.CommPort = i1
    MSComm1.PortOpen = True
    MSComm1.InputMode = comInputModeBinary
    MSComm1.InBufferCount = 0
& ......

Delphi 与 C/C++ 数据类型对照表

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 ......

C/C++传递二维数组

C/C++传递二维数组 - [IT资料]
//c语言中经常需要通过函数传递二维数组,有三种方法可以实现,如下:
//方法一, 形参给出第二维的长度。
#include <stdio.h>
void func(int n, char str[][5])
{
           int i;
      & ......

基于S3C2440的Linux内核移植和yaffs2文件系统制作

  基于S3C2440的Linux内核移植和yaffs2文件系统制作 收藏
Linux内核移植和根文件系统制作
第一章 移植内核... 2
1.1 Linux内核基础知识... 2
1.1.1  Linux版本... 2
1.1.2 什么是标准内核... 2
1.1.3 Linux操作系统的分类... 3
1.1.4 linux内核的选择... 4
1.2 Linux内核启动过程概述... 5
1.2.1  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号