Removing the C run-time library (RTL)

2006-10-30 | Removing the C run-time library (RTL)

Removing the C run-time library (RTL)

This is pretty straight forward. Just click on the "Ignore all default libraries" in the Link tab in your project settings, or use the "/NODEFAULTLIB" linker setting. However, you probably wont be able to compile your project any more.

Visual C++ requires that you provide three functions (for a normal C program): __purecall, new and delete. A C program requires malloc and free. Obviously, if you don't do ANY memory allocation then you don't need them. Here are minimal implementations of these functions:

void * __cdecl operator new(unsigned int bytes)
{
  return HeapAlloc(GetProcessHeap(), 0, bytes);
}

void __cdecl operator delete(void *ptr)
{
  if(ptr) HeapFree(GetProcessHeap(), 0, ptr);
}

extern "C" int __cdecl __purecall(void)
{
  return 0;
}

This just leaves the entry-point functions. Define which ever one is required by the type of executable you are building. At the very least, your entry-point function must call either main WinMain or DllMain.

int  __cdecl mainCRTStartup();
int  __cdecl WinMainCRTStartup();
BOOL __cdecl _DllMainCRTStartup(HINSTANCE, DWORD, LPVOID);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值