基于pspad和tcc的小巧编译器

小巧而纯粹的c语言编译器配置,整个IDE才10M左右大小。

一、编译器设定

1.     下载pspad/tcc

     Pspad: http://www.pspad.com

     Tcc : http://download.savannah.gnu.org/releases/tinycc/

     tcc-0.9.26-win32-bin.zip

2.以管理员身份运行pspad,设置编译选项

 

3.设置编译快捷键

设置—>首选项—>热键对应—>File—>编译

 

二.编译器测试

1.九九乘法表

/***Author:piaoxiang.zhang****/

#include<stdio.h>

void main(void)

{

 system("Title 九九乘法表");

 for(int i=1;i<10;i++){

   for(int j=1;j<=i;j++)

       printf("%d*%d=%-2d\t",i,j,i*j);   

   printf("\n");

 }

 system("pause\n");//程序窗口暂停,否则看不到输出。

}

 

2.混合汇编

Tcc 支持AT&T格式的汇编代码。

/****Author:piaoxiang.zhang******/
#include <stdio.h>
#include <stdlib.h>
#define SWH_16(arg) swap_half_16_##arg
#define funVar(xxx) printf( "%s initial data is:\n", #xxx )
void swap_half_16_4th(uint16_t *data,int len)
{
 printf("\n%s start:\n",__func__) ;
 uint8_t *tmp=(uint8_t *) data;
 while(len>0)
 {
   __asm( "movb  0(%%esi),%%ah\n\t"
          "movb  1(%%esi),%%al\n\t"
          "movw   %%ax,(%%esi)\n\t" 
          :"+a"(data)
          :"S"(tmp));
    tmp+=2;
    len--; 
 }   
}
int main(int argv ,char **argc)
{
  uint16_t data[4]={0x1312,0x1512,0x1712,0x1812};
  SWH_16(4th)(data,4);    
printf("0x%X,0x%X,0x%X,0x%X\n",data[0],data[1],data[2],
data[3]); 
  system("pause"); 
  return 0 ;
}
 

 

3.     window 编程:

一个最简单的windows dialog

/*-------(c) Charles Petzold, 1998---------------------*/
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
{
  MessageBox(NULL,TEXT("莫失莫忘,仙寿恒昌。\n不离不弃,芳龄永继。"),TEXT("石头记"),0);
   return 0 ;
}
 

 

4.     动态链接库。

以OpenGL 为例:

让编译器链接opengl 动态库

 
 

/********来源于网络,具体来源忘记了,sorry,稍有修改******/
#include <windows.h>
#include <gl/gl.h>
 
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
 
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;        
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLSample";
    RegisterClass (&wc);
    hWnd=CreateWindow ("GLSample", "OpenGL Sample", 
            WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
                          300, 100, 512, 512,
                          NULL, NULL, hInstance, NULL);
    EnableOpenGL (hWnd, &hDC, &hRC);
    while (!bQuit)
    {  
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)){
            if (msg.message == WM_QUIT)
                bQuit = TRUE;
            else{
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else{          
            glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);
            glPushMatrix ();
            glRotatef (theta, 0.0f, 0.0f, 1.0f);
            glBegin (GL_TRIANGLES);
            glColor3f (1.0f, 0.0f, 0.0f);   
glVertex2f (0.0f, 1.0f);
            glColor3f (0.0f, 1.0f, 0.0f);   
glVertex2f (0.87f, -0.5f);
            glColor3f (0.0f, 0.0f, 1.0f);   
glVertex2f (-0.87f, -0.5f);
            glEnd ();
            glPopMatrix ();
            SwapBuffers (hDC);
            theta += 1.0f;
            Sleep (1);
        }
    }
    DisableOpenGL (hWnd, hDC, hRC);
    DestroyWindow (hWnd);
    return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam)
{
    switch (message){
          case WM_CREATE:return 0;
          case WM_CLOSE:PostQuitMessage (0); return 0;
          case WM_DESTROY:return 0;
          case WM_KEYDOWN:
              switch (wParam){
                case VK_ESCAPE:PostQuitMessage(0);return 0;
              }
              return 0;
          default:
          return DefWindowProc(hWnd,message,wParam, lParam);
    }
}
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;
    *hDC = GetDC (hWnd);
    ZeroMemory (&pfd, sizeof (pfd));
    pfd.nSize = sizeof (pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | 
      PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    iFormat = ChoosePixelFormat (*hDC, &pfd);
    SetPixelFormat (*hDC, iFormat, &pfd);
    *hRC = wglCreateContext( *hDC );
    wglMakeCurrent( *hDC, *hRC );
}
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
    wglMakeCurrent (NULL, NULL);
    wglDeleteContext (hRC);
    ReleaseDC (hWnd, hDC);
}
 

 

5.     为程序添加图标。

需要用到Gcc 组件里的windres 程序。

 

准备以下文件

 

Music.rc

#include <windows.h>

#define IDI_SMLWIN 101

IDI_SMLWIN ICONDISCARDABLE "music_disk_SH.ico"

编译music.rc 得到music.res

/********Author:piaoxiang.zhang*******/
#include <windows.h>
int main()
{
  printf("愿你出走半生,归来仍是少年。\n携一人白首,择一城终老。\n");
  system("pause");
  return 0;
}

 

 

 

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值