??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲今日精彩视频,亚洲一卡二卡三卡四卡无卡麻豆 ,亚洲国产精品精华液http://m.tkk7.com/bluesky/category/5633.html做好软gZ? #gcc -c helloworld.c -o helloworld.o //~译目标文g #gcc helloworld.o -o helloworld //~译成可执行exe #helloworld //q行exezh-cnTue, 27 Feb 2007 20:41:31 GMTTue, 27 Feb 2007 20:41:31 GMT60C++libs http://m.tkk7.com/bluesky/archive/2006/06/01/49530.htmlblueskyblueskyThu, 01 Jun 2006 04:48:00 GMThttp://m.tkk7.com/bluesky/archive/2006/06/01/49530.htmlhttp://m.tkk7.com/bluesky/comments/49530.htmlhttp://m.tkk7.com/bluesky/archive/2006/06/01/49530.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/49530.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/49530.html
http://www.libsdl.org/
http://www.wxwidgets.org/
http://www.fltk.org/
http://www.boost.org/
http://www.zlib.net/
http://expat.sourceforge.net/
http://www.eskimo.com/~weidai/cryptlib.html
http://glut.org/
http://gborg.postgresql.org/project/libpqxx/projdisplay.php
http://www.sgi.com/tech/stl/
http://stlport.org/
http://sourceforge.net/projects/blitz/
http://www.cs.wustl.edu/~schmidt/ACE.html
http://www.sourceforge.net/projects/tinyxml


http://www.tinybutstrong.com/ [a php templates engine]


bluesky 2006-06-01 12:48 发表评论
]]>
Minimal wxWidgets sample~~http://m.tkk7.com/bluesky/archive/2006/05/15/46144.htmlblueskyblueskySun, 14 May 2006 16:00:00 GMThttp://m.tkk7.com/bluesky/archive/2006/05/15/46144.htmlhttp://m.tkk7.com/bluesky/comments/46144.htmlhttp://m.tkk7.com/bluesky/archive/2006/05/15/46144.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/46144.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/46144.html/////////////////////////////////////////////////////////////////////////////
// Name:        minimal.cpp
// Purpose:     Minimal wxWidgets sample
// Author:      Julian Smart
// Modified by:
// Created:     04/01/98
// RCS-ID:      $Id: minimal.cpp,v 1.67 2005/02/20 16:14:03 JS Exp $
// Copyright:   (c) Julian Smart
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

// ============================================================================
// declarations
// ============================================================================

// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------

// For compilers that support precompilation, includes "wx/wx.h".
#include <string>
#include <iostream>
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------

// the application icon (under Windows and OS/2 it is in resources and even
// though we could still include the XPM here it would be unused)
#if !defined(__WXMSW__) && !defined(__WXPM__)
    #include "sample.xpm"
#endif

// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------

// Define a new application type, each program should derive a class from wxApp
class MyApp : public wxApp
{
public:
    // override base class virtuals
    // ----------------------------

    // this one is called on application startup and is a good place for the app
    // initialization (doing it here and not in the ctor allows to have an error
    // return: if OnInit() returns false, the application terminates)
    virtual bool OnInit();
};

// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
    // ctor(s)
    MyFrame(const wxString& title);
 wxButton *WxButton1;
    wxTextCtrl *wxTextCtrl1;
        wxTextCtrl *wxTextCtrl2;
    // event handlers (these functions should _not_ be virtual)
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
void WxButton1Click(wxCommandEvent& event);
private:
    // any class wishing to process wxWidgets events must use this macro
    DECLARE_EVENT_TABLE()
};

// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------

// IDs for the controls and the menu commands
enum
{
 ID_WXBUTTON1 = 1001,
    // menu items
   
    Minimal_Quit = wxID_EXIT,

    // it is important for the id corresponding to the "About" command to have
    // this standard value as otherwise it won't be handled properly under Mac
    // (where it is special and put into the "Apple" menu)
    Minimal_About = wxID_ABOUT

};

// ----------------------------------------------------------------------------
// event tables and other macros for wxWidgets
// ----------------------------------------------------------------------------

// the event tables connect the wxWidgets events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
    EVT_MENU(Minimal_About, MyFrame::OnAbout)
    EVT_BUTTON(ID_WXBUTTON1,MyFrame::WxButton1Click)
END_EVENT_TABLE()

// Create a new application object: this macro will allow wxWidgets to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also implements the accessor function
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
// not wxApp)
IMPLEMENT_APP(MyApp)

// ============================================================================
// implementation
// ============================================================================

// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------

// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
    // create the main application window
    MyFrame *frame = new MyFrame(_T("helloworld-test"));

    // and show it (the frames, unlike simple controls, are not shown when
    // created initially)
    frame->Show(true);

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here, the
    // application would exit immediately.
    return true;
}

// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------

// frame constructor
MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title)
{

    // set the frame icon
    SetIcon(wxICON(sample));

#if wxUSE_MENUS
    wxMenu *fileMenu = new wxMenu;
    wxMenu *helpMenu = new wxMenu;
    helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog"));

    fileMenu->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));


    wxMenuBar *menuBar = new wxMenuBar();
    menuBar->Append(fileMenu, _T("&pȝ"));
    menuBar->Append(helpMenu, _T("&帮助"));

    // ... and attach this menu bar to the frame
    SetMenuBar(menuBar);
  
#endif // wxUSE_MENUS

#if wxUSE_STATUSBAR
    // create a status bar just for fun (by default with 1 pane only)
    CreateStatusBar(2);
    SetStatusText(_T("helloworld-test"));
#endif // wxUSE_STATUSBAR
 wxPanel* p = new wxPanel(this, -1);
   wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
   
   
/*    topsizer->Add(
    new wxStaticText( p, wxID_ANY, _T("An explanation (wxALIGN_RIGHT).") ),
    wxSizerFlags().Align(wxALIGN_RIGHT).Border(wxALL & ~wxBOTTOM, 5));


  topsizer->Add(
    new wxTextCtrl( p, wxID_ANY, _T("My text (wxEXPAND)."), wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE),
    wxSizerFlags(1).Expand().Border(wxALL, 5));


  wxBoxSizer *statsizer = new wxStaticBoxSizer(
    new wxStaticBox(p, wxID_ANY, _T("A wxStaticBoxSizer")), wxVERTICAL );
  statsizer->Add(
    new wxStaticText(p, wxID_ANY, _T("And some TEXT inside it")),
    wxSizerFlags().Center().Border(wxALL, 30));
  topsizer->Add(
    statsizer,
    wxSizerFlags(1).Expand().Border(wxALL, 10));*/
   
   
    wxGridSizer *gridsizer = new wxGridSizer(2, 5, 5);
   
    gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Label")),
                   wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL));
                   wxTextCtrl1 = new wxTextCtrl(p, wxID_ANY, _T(""));
    gridsizer->Add(wxTextCtrl1,
                   wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL));
    gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Another label")),
                   wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL));
                  
                   wxTextCtrl2 = new wxTextCtrl(p, wxID_ANY, _T(""));
                  
    gridsizer->Add(wxTextCtrl2,
                   wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL));
    gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Final label")),
                   wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL));
    gridsizer->Add(new wxTextCtrl(p, wxID_ANY, _T("")),
                   wxSizerFlags().Align(wxGROW | wxALIGN_CENTER_VERTICAL));
     topsizer->Add(
        gridsizer,
        wxSizerFlags().Proportion(1).Expand().Border(wxALL, 10));
       
     wxBoxSizer *button_box = new wxBoxSizer( wxHORIZONTAL );
  button_box->Add(
     new wxButton( p, wxID_ANY, _T("Two buttons in a box") ),
     wxSizerFlags().Border(wxALL, 7));
    
 
   WxButton1 = new wxButton(p, ID_WXBUTTON1, _T("WxButton1"), wxPoint(142,184), wxSize(75,25), 0, wxDefaultValidator, wxT("WxButton1"));
 
       button_box->Add(WxButton1,  wxSizerFlags().Border(wxALL, 7));
  button_box->Add(
     new wxButton( p, wxID_ANY, _T("(wxCENTER)") ),
     wxSizerFlags().Border(wxALL, 7));

  topsizer->Add(button_box, wxSizerFlags().Center());

  p->SetSizer( topsizer );
 

      topsizer->SetSizeHints( this );
   

}


// event handlers

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    // true is to force the frame to close
    Close(true);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxString msg;
    msg.Printf( _T("helloworld-test.\n")
                _T("helloworld-test"));
               

    wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
}
void MyFrame::WxButton1Click(wxCommandEvent&  WXUNUSED(event))
{
 


 wxString n1 = wxTextCtrl1->GetValue();
 wxString n2 = wxTextCtrl1->GetValue();
 std::string nx = (std::string)n1;
 std::cout << nx <<std::endl;
 wxString msg;
 msg.Printf( _T(n1));

    wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
}



bluesky 2006-05-15 00:00 发表评论
]]>
使用libpqxxȝhttp://m.tkk7.com/bluesky/archive/2006/05/11/45612.htmlblueskyblueskyThu, 11 May 2006 02:52:00 GMThttp://m.tkk7.com/bluesky/archive/2006/05/11/45612.htmlhttp://m.tkk7.com/bluesky/comments/45612.htmlhttp://m.tkk7.com/bluesky/archive/2006/05/11/45612.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/45612.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/45612.htmlUsing libpq(c api) and libpqxx(c++ api) to connect postgresql-8.1.3 on WindowsXP
need MinGW Msys postgresql-8.1.3 source baggage
I use libpqxx-2.5.5 look at the libpqxx-2.5.5\win32\Intall.txt

--------------------------------------------------------------------
Getting Started with MinGW and MSYS
(based on contribution by Michael J. Pedersen, 2004-08-17)

MSYS is a Unix-like environment for Windows.  Once you have this installed,
building libpqxx should be a lot more like it is under Unix except that the
locations of libraries and such aren't sufficiently standardized.

Packages to download if you don't have them already:
1) MinGW (http://www.mingw.org/), plus any updates.
2) MSYS (http://www.mingw.org/), again with any updates.
3) w32api (http://www.mingw.org/).
4) PostgreSQL (http://www.postgresql.org/).
5) zlib (http://www.zlib.org/).

It is generally recommended to get the latest versions of these packages.

Compiling and installing PostgreSQL before you get to libpqxx:
1) Install MinGW (install to c:\mingw)
2) Install MSYS--but not into MinGW directory tree!
3) Run MSYS (Start->Programs->MinGW->MSYS->msys)
4) Extract, compile, and install zlib
    # From main source directory of zlib:
    ./configure --prefix=c:/mingw/local && make && make install
5) Extract, compile, and install postgres
    # From main source directory of PostgreSQL:
    ./configure --prefix=c:/mingw/local --with-includes=c:/mingw/local/include --with-libs=c:/mingw/local/lib  && make && make install
   重要:把C:\mingw\local\bin讄环境变量PATH?br />6) Extract, compile, and install libpqxx
    export LDFLAGS=-lws2_32 &&  ./configure --prefix=c:/mingw/local --disable-shared --enable-static --disable-thread-safety && make && make install
---------------------------------------------------------------------
   
 Uing it in eclpise cdt
 1、设|环境变量PATH C:\mingw\local\lib 使程序能q接到libpq.dll
 2?nbsp;-I "C:\MinGW\local\include"
  -I "C:\MinGW\libpqxx-2.5.5\include"
 3?nbsp;-l  
   pqxx
   pq
   ws2_32
   wsock32
   注意序
  -L 
   "C:\MinGW\local\lib"
   "C:\MinGW\lib"
 4、测试代?br /> pqlib C?\postgresql-8.1.3\src\test\examples
 pqlibxx C++ libpqxx-2.5.5\test    

   



bluesky 2006-05-11 10:52 发表评论
]]>
use eclipse to develope c or c++ On Windows platformhttp://m.tkk7.com/bluesky/archive/2006/05/09/45146.htmlblueskyblueskyTue, 09 May 2006 01:40:00 GMThttp://m.tkk7.com/bluesky/archive/2006/05/09/45146.htmlhttp://m.tkk7.com/bluesky/comments/45146.htmlhttp://m.tkk7.com/bluesky/archive/2006/05/09/45146.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/45146.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/45146.htmluse eclipse to develope c or c++ On Windows platform
of course you need j2sdk
1 download eclipse platform and cdt plugins from eclipse official site http://www.eclipse.org/
2 download GNU c/c++ compilers I use MinGW http://www.mingw.org
I use the MinGW-3.1.0-1.exe
2.1 Install MinGW say:D:/MinGW
2.2 set environment
 
 Path D:\MinGW\bin;
 C_INCLUDE_PATH D:\MinGW\include;
 CPLUS_INCLUDE_PATH  D:\MinGW\include\c++\3.2.3;D:\MinGW\include\c++\3.2.3\mingw32;D:\MinGW\include\c++\3.2.3\backward;D:\MinGW\include;
 LIBRARY_PATH D:\MinGW\lib;
 change the D:\MinGW\bin\mingw32-make.exe file name to make.exe
 
3 also download the Msys from MinGW.org
3.1 Install Msys

4 downloads wxWidgets-2.6.3.zip from http://www.wxwidgets.org/ 
4.1 building it
 unzip it first say:D:\MinGW\wxWidgets-2.6.3
 > cd D:\MinGW\wxWidgets-2.6.3\build\msw
   > make -f makefile.gcc BUILD=release
   > cd D:\MinGW\wxWidgets-2.6.3\samples\minimal
   > make -f makefile.gcc BUILD=release
4.2 use wxWidgets-2.6.3 in eclipse
 Properties for a c++ project
 GCC C++ Compiler
  Preprocessor(-D)  _WINDOWS
     WIN32
     __WIN95__
  Directories  "D:\MinGW\lib\gcc-lib\mingw32\3.2.3\include"
     "D:\MinGW\wxWidgets-2.6.3\include"
     "D:\MinGW\wxWidgets-2.6.3\lib\gcc_lib\msw"
 GCC C++ Linker
  Libraries
   Libraries(-l)
    wxmsw26_adv
    wxmsw26_core
    wxbase26
    wxtiff
    wxjpeg
    wxpng
    wxzlib
    wxregex
    wxexpat
    kernel32
    user32
    gdi32
    comdlg32
    winspool
    winmm
    shell32
    comctl32
    ole32
    oleaut32
    uuid
    rpcrt4
    advapi32
    wsock32
    odbc32
   Library search path(-L)
    "D:\MinGW\lib"
    "D:\MinGW\wxWidgets-2.6.3\lib\gcc_lib"

5 Install some libs tools on eclpise
ACE_wrappers build with Msys  http://www.cs.wustl.edu/~schmidt/ACE.html
mysql++-2.1.1 build with makefile and need the mysql source src zip file http://www.tangentsoft.net/mysql++/ 
STLport-4.6.2 http://stlport.org
STLsgi-3.3 http://www.sgi.com/tech/stl
boost_1_33_1   http://www.boost.org/

look the readme file will help you build


http://www.freebyte.com/programming/cpp/



bluesky 2006-05-09 09:40 发表评论
]]>
Visual C++ ActiveX Control for hosting Office documents in Visual Basic or HTMLhttp://m.tkk7.com/bluesky/archive/2006/04/27/43457.htmlblueskyblueskyThu, 27 Apr 2006 01:03:00 GMThttp://m.tkk7.com/bluesky/archive/2006/04/27/43457.htmlhttp://m.tkk7.com/bluesky/comments/43457.htmlhttp://m.tkk7.com/bluesky/archive/2006/04/27/43457.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/43457.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/43457.htmlhttp://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q311/7/65.asp&NoWebContent=1

bluesky 2006-04-27 09:03 发表评论
]]>
Free C++ (and C)http://m.tkk7.com/bluesky/archive/2006/04/24/42832.htmlblueskyblueskyMon, 24 Apr 2006 06:54:00 GMThttp://m.tkk7.com/bluesky/archive/2006/04/24/42832.htmlhttp://m.tkk7.com/bluesky/comments/42832.htmlhttp://m.tkk7.com/bluesky/archive/2006/04/24/42832.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/42832.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/42832.htmlhttp://www.freebyte.com/programming/cpp/

Anjuta Free open-source IDE for C and C++ on Linux/GTK/GNOME.
Borland C++ This well known compiler from Borland (for Windows and DOS) can now be downloaded for free (legally)!
Code::Blocks Studio A freeware open-source C++ IDE for Windows and Linux. It supports these compilers: GCC (MingW / Linux GCC), MSVC++, Digital Mars, Borland C++ 5.5, Open Watcom.
Dev-C++ A full-featured Integrated Development Environment (IDE) for the C/C++ programming language. Freeware for Windows.
DevelopGo For Linux. Over 11 Languages, 5 popular Integrated Development Environments, 4 GUI designers, 5 GUI toolkits, extensive language bindings, wide collection of offline documentation and with core Onebase support all in a Single LiveCD. After signing up for a $10 download account, have free access to all Onebase Products, including upgrades.
Digital Mars Free C and C++ Compilers and IDE's for Win32, Win16, DOS32 and DOS, command line and GUI versions, tutorials, sample code, online updates, Standard Template Library, etc.
djgpp A port of the GNU compiler and programming tools to MS DOS.
Eclipse CDT C and C++ Integrated Development Environment (IDE) for the Eclipse platform implemented in Java.
Embedded Visual C++ Free Visual C++ compiler for Windows Mobile and Windows CE.
GNU C++/C Compiler GCC, the GNU Compiler Collection (freeware, open source, multi-platform), includes front ends for C, C++, Objective-C, Fortran, Java, and Ada. The GCC documentation section can be found here.
Intel C++ compiler Free Linux C++ compiler from Intel. Freeware for non-commercial use. It uses either the command line or the optional Eclipse-based integrated development environment (Eclipse IDE runs on IA-32 only).
KDevelop Free open-source IDE for Linux/KDE which supports many programming languages.
LCC-Win Free C compiler/IDE for Windows . Contains compiler, debugger, resource compiler, resource editor, etc etc. Freeware for non-commercial use only.
Macintosh
Programmer's Workshop
Free C++ compilers, debuggers, assemblers, documentation and related tools for the MAC platform.
MinGW 'Minimalist GNU for Windows'. A collection of freely available and freely distributable Windows specific header files and import libraries combined with GNU toolsets that allow one to produce native Windows programs that do not rely on any 3rd-party C runtime DLLs. MinGW comes with the GNU C++ compiler.
See also GCC/GCJ for MingW.
MinGW Developer Studio An IDE for the GNU C/C++ Compiler. Freeware for Windows and Linux.
Open Watcom Freeware open source C++ (and Fortran) compilers for Windows. Plans for Open Watcom include porting the compiler to the Linux and FreeBSD platforms
Pelles C A complete development kit for Windows and Pocket PC. It contains an IDE, optimizing C compiler, a linker, a resource compiler, a message compiler, a make utility, a debugger, install builders and much more. For Windows and Pocket PC.
Relo A Windows C/C++ IDE for MinGW and Borland C++ compilers. Freeware, open-source for Windows.
Rhide An IDE with which you can develop and debug in C, C++, Pascal and other languages and compilers which can be called from Rhide. Suitable for Linux text-console and DOS / DJGPP.
Tiny C Compiler Freeware, small and fast C-compiler for Linux.
Ultimate++ Ultimate++ consists of Set of cross-platform Windows and Linux libraries ("packages"), widgets (user-interface elements) an IDE, a lay-out designer for designing dialogs, image designer for designing graphical elements, language editor for managing internationalized text strings, etc.
V IDE Integrated Development Environment for the GNU g++ compiler, Borland C++ 5.5, and the standard Sun Java Development Kit. Suitable for Windows and Linux.
Visual C++ Express Free Visual C++ compiler for Windows by Microsoft.
Visual-MinGW Freeware open-source IDE for Windows. An Integrated Development Environment for MinGW compiler.
WideStudio An open source, Integrated Development Environment for developing GUI applications based on the MWT(Multi-Platform Widget Toolkit). Supported platforms: Windows, WindowsCE, Linux, FreeBSD, SOLARIS, MacOSX, etc.
wx-Devcpp wxWidgets form designer plugin for Dev-C++ which can help you to create Dialogs and Frames for wxWidgets visually.
XCode Integrated development environment (IDE) for creating Mac OS X Universal Binaries that run natively on PowerPC and Intel-based Macintosh computers. Freeware.

Non-free C++ Compilers and IDE's
Code Forge Professional Integrated Development Environment for Unix/Linux with project management features and edit/compile/debug support for over 30 programming languages. The IDE has preconfigured support for all major free and commercial compilers on the market today, such as GCC.
Code Crusader IDE for Linux-Intel, Linux-PPC and Solaris. Supports over 30 programming languages. It comes with the JX GUI Application framework, which is built directly on top of Xlib.
 
Free C++ GUI Libraries
FLTK A cross-platform C++ GUI toolkit for UNIX/Linux, Windows, and MacOS X providing modern GUI functionality without the usual bloat. It also supports 3D graphics via OpenGL and its built-in GLUT emulation.
Fox Toolkit Cross-platform C++ user-interface library, freeware, open-source.
LGI Cross-platform C++ framework for abstracting out all the operating system dependencies that you can produce portable code. It handles all the graphical interface functions, threading and semaphores, network connectivity and lots of other bits and pieces to help build small, fast and reliable applications.
Qt Cross-platform C++ GUI framework.
Scintilla A free source code editing component. Freeware, open-source for Linux and Windows.
The GUI Toolkit,
Framework Page
A comprehensive reference on toolkits for building graphical user interfaces (GUIs), with emphasis on resources for Free Software (Open Source)
V V is a free, multiple platform C++ graphical user interface framework designed to make it easy to write C++ GUI applications, commercial, shareware, or freeware. V is available for X Athena, X Motif/Lesstif, all Windows platforms, and OS/2.
Whisper2 C++ application framework for the Mac, Unix and Windows.
wxWidgets API for writing GUI applications on multiple platforms. Link with the appropriate library for your platform (Windows/Unix/Mac, others coming shortly) and compiler (almost any popular C++ compiler), and your application will adopt the look and feel appropriate to that platform. Additionally: online help, network programming, streams, clipboard and drag and drop, multi-threading, image loading and saving in a variety of popular formats, database support, HTML viewing and printing, etc. Freeware, Open Source
ZooLib A cross-platform application framework, enables you to write a single set of C++ sources and compile them to native executables to run on MacOS, Windows, BeOS or Unix/Linux.
 
Free C++ Database Libraries
DataReel A cross-platform C++ development kit used to build multi-threaded database and communications applications. Using DataReel you can build end-user applications, embedded systems, and reusable libraries for multiple operating systems.
DiamondBase C++ database engine which is available for free non commercial use, and is negotiable for commercial use.
MySQL++ MySQL++ is a C++ wrapper for MySQL's API.
SQLLite SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine.
 
Free C++ Compression Libraries
libmspack Portable C++ library which provides compression and decompression of some file formats used by Microsoft (.cab, .hlp, .chm, compress.exe, etc).
UCL UCL is a portable lossless data compression library written in ANSI C. UCL implements a number of compression algorithms that achieve an excellent compression ratio while allowing *very* fast decompression. Decompression requires no additional memory.
ZipArchive Free zip/unzip C-library.
ZLib Free zip/unzip C-library.
 
Free C++ Graphics and Game Libraries
Amanith Framework A cross-platform (Linux, Win32, Mac OX X, FreeBSD, Linux and IRIX) open source C++ framework for 2D and 3D vector graphics that includes 2D curves, a 2D font engine, bitmap vectorizer, tessellator, and an OpenGL extensions manager.
OGRE 3D Open source 3D-graphics and game engine for Linux, MAC and Windows.
OpenGL Excellent high-performance cross-platform 3D graphics library. Elegant API. It can be used for a variety of purposes, such as: animations, virtual reality, game-programming, simulations, etc.
Real-Time Oscilloscope
DLL Library
Freeware real-time Windows Oscilloscope DLL with an API for C++ , Delphi, MathWorks Matlab and Simulink.


bluesky 2006-04-24 14:54 发表评论
]]>
计算机组成原理讲E? 概述)http://m.tkk7.com/bluesky/archive/2006/02/16/30915.htmlblueskyblueskyThu, 16 Feb 2006 02:10:00 GMThttp://m.tkk7.com/bluesky/archive/2006/02/16/30915.htmlhttp://m.tkk7.com/bluesky/comments/30915.htmlhttp://m.tkk7.com/bluesky/archive/2006/02/16/30915.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/30915.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/30915.html???l?????E?br />?Ԍ王健
http://www.seuyc.com.cn/course/kcjg/jsjzcyl/jsjzz.htm

W一?nbsp;    概述
1.计算机由q算器、存储器、控制器和输?输出五个部gl成?br />2.?middot;ZD机的主要特点:
1Q计机p器、存储器、控制器和输?输出五个部gl成?
2Q存储器以二q制形式存储指o和数据;
3Q存储程序工作方式;
4Q五部g以运器Z心进行组l;

W??nbsp; 数据的表C?br />1.在计机pȝ中,凡是要进行处理(包括计算、查找、排序、分cR统计、合q等Q、存储和传输的信息,都是用二q制q行~码的?
2.q位计数制及其各q位制数之间的{?br />3.定点与Q点表C的Ҏ、特?
4.机器数的三种~码表示方式Q原码、补码和反码?nbsp;    定义、特炏V用途?br />5.点数的~码表示及规格化
6.十进制数的二q制~码表示?BCD码的特点
7.字符及汉字的~码Ҏ、特?
8.音频、视频的~码Ҏ及特?br />9.数据校验码的用?/p>

W??q算器与q算Ҏ
1. q算器基本组成和功能
2.半加器与全加器的逻辑设计
3.串行q位与ƈ行进位的比较
4.补码定点加、减?br />5.原码一位乘?br />6.补码一位乘?br />7.点加、减?/p>

W??nbsp; 存储pȝ
1.存储器的主要性能指标
2.存储pȝ的层ơ结?br />3.半导体读写存储器RAM芯片的结构、组成及存储器系l的构成
4.半导体只d储器的特点及分类
5.高速缓冲存储器Cache的工作原理、映方式、替换算法,了解Pentium Cache l构和Power PC Cache l构?
. 虚拟存储器的功能、基本管理方法、结?.表面存储器的性能指标、硬盘存储器的基本l成、信息分布、硬盘容量和数据传输率的计算

W??nbsp; 指opȝ
1. 指o格式、指令长?
2.常用的寻址方式U类、特炏V用?
3.指opȝ的地位、作用,指ocd
4.堆栈的定义、用途和堆栈存取方式
5. CISC与RISC指o各自的特点和比较

W??nbsp; 中央处理机组l?
1. CPU的组成与操作Q单ȝl织的数据通\及四U基本功能?br />2.控制器三U时序控制方式:同步、异步和联合控制方式?br />3.三种时序信号周期、节拍和脉冲的概c作?br />4.控制器的l成和功?br />5.一条完整指令执行的控制步序?br />6.军_CPU性能最重要的三个因素:指o的功能强弱、时钟周期的长短、执行每条指令所需旉周期数?br />7.指o水的概?br />8.l合逻辑控制器的构成与设计步?br />9.微程序控制器的原理、基本概c基本组l和工作程
10.微指令的两种格式?U编?br />11.两种微指令地址的生成方?br />12.微程序控制器和组合逻辑控制器的比较

W??nbsp; ȝ及ȝ互连l构
1.ȝ的基本概c作用和分类
2.ȝ的两U传输方?-串行和ƈ行的特点
3.ȝ裁决的意义及分类
4.ȝ定时方式的分cd特点
5.影响ȝ带宽的因?br />6.单ȝl构和多ȝ分层l构的比?/p>

W??nbsp; 输入输出讑֤

W??输入输出l织
1. I/O接口的功能、结构和分类
2. I/O端口~址的两U方法的比较
3. 四种I/O数据传送控制方式的比较
4.E序查询方式的特?br />5.中断的概c分cR中断优先Q开关中断和中断屏蔽
6.中断q程Q中断响应和中断处理
7.中断pȝ的基本结构和功能
8.中断嵌套和向量中?
9.DMA方式的概念和适用范围
10.DMA方式和中断方式的比较
11.DMA方式的概念和适用范围
12.三种DMA方式的特?br />13. DMA接口的结构和功能
14.通道的基本概c用途和分类

W一?nbsp;    概述

计算机是一U能Ҏ字化信息q行自动高速运的通用处理装置?/p>

1Q?  计算机的定义和特?信息  q算  处理

1.1.1 什么是计算?
1.1.2 计算机的Ҏ?
计算机的Ҏ可以归Uؓ高速、通用、准?四大Ҏ?/p>

1Q?  计算机的发展历程
1.2.1 电子计算机的诞生
W一台电子计机ENIACQElectronic Numerical  Integrator and ComputerQ于1946q在国诞生?
①每U?000ơ加法运;
②每U?0ơ乘法运;
③^方和立方计算Q?
④Sin和Cos函数数D;
⑤其它更复杂的计?nbsp;

1.2.2  W一代计机   Q?0世纪40q代中到50q代末)
W一代计机为电子管计算机,光辑元g采用电子 ,存储器g为声延迟U或鼓Q典型逻辑l构为定 点运?br />计算?ldquo;软g”一词尚未出玎ͼ~制E序所?工具ZU语a?

1.2.3  W二代计机Q?0q代中后期到60q代中)
W二代计机为晶体管计算机。这一代计机除了?辑元仉用晶体管以外Q其内存储器q芯构成,?鼓与带成ؓ外存储器?/p>

计算机典型逻辑l构实现了Q点运, q提Z变址、中断、I/O处理{新概念?
计算Y件也得到了发展,出现了多U?高语言及其~译E序?/p>

1.2.4 W三代计机Q?0q代中到70q代中)
W三代计机为集成电路计机Q其逻辑元g与存储器 均由集成电\实现Q这是微电子与计机技术相l合?一大突破?br />微程序控制、高速缓存、虚拟存储器、流?U等先进计算机技术开始用。另一大特Ҏ大型/?型机与小型机同时发展?/p>

1.2.5 W四代计机Q?0q代中期开?mdash;Q?
大规模(LSIQ和大规模QVLSIQ集成电?及微处理器ؓq一代计机的典型特征?br />q行处理技术的研究与应用以及众多巨型机的生也?一时期计算机发展的特点?
四代机时期的一个重要特Ҏ计算机网l的发展与广?应用?

1.2.6 C代计机 新器件和非冯·Z曼结构已成ؓC代计机的公认标志?/p>

1Q?  计算机的l成与结?

1.3.1 计算机系l的层次l构

6应用pȝ法和数字模?br />---------------------
5各种应用E序
---------------------
4高E序~译,解释E序
---------------------
3操作pȝ
---------------------
2指opȝ
---------------------
1微程序控?PLA控制
---------------------
0逻辑g

1.3.2 计算机硬?br />计算机硬件是指构成计机的元器g?部g、设备、以及它们的设计与实现技术?
?middot;ZD机的主要特点: 1Q计机p器、存储器、控制器和输?输出五个    部gl成?/p>

本书讨论的范围涉及第0???层, 主要内容如下Q?
1. 高速的术、逻辑q算Ҏ及ALU?nbsp;   逻辑设计Q?
2. 高速的指o执行q程及指令部件的设计与实玎ͼ    是采用组合逻辑技术、或微程序设计技术,q是    PLA技术;
是复杂指令集计算机(CISCQ,q是    _指o集计机QRISCQ;
3. 提高存储器容量与速度的方法,以及如何解决    “CPU-Cache-MM-外存”之间的匹配问题;
4. 高效率的输入/输出Ҏ、组l,以及它们之间?nbsp;   互联技术;
5. 计算Z大部Ӟq算器、控制器、存储器、输?nbsp;   和输出)之间的相互作用、高效接口(ȝQ;

2Q存储器以二q制形式存储指o和数据;
3Q存储程序工作方式;
4Q五部g以运器Z心进行组l;

1.3.3 计算Y?
1. 软g的作?
一般来_计算机的工作L由存储程序来控制的?

软g的具体作用ؓQ?br />①在计算机系l中L指挥和管理的作用?
②是计算机用户和g的接口界面?
③是计算Zpȝ构设计的主要依据?/p>

2. 软g的发展过E?三个阶段Q?
1)从第一台计机上的W一个程序出现到 实用的高U语a出现为第一阶段Q?946-1956q_?
2)从实用的高E序设计语言出现到Y件工E出?以前为第二阶D(1956-1968q_?
3)软g工程出现以后q今一直ؓW三阶段Q?965—Q?

3. 软g的分c?
?pȝ软gQ操作系l、编译程序?
?支撑软gQ数据库、各cL口Y件和工具l?
?应用软gQ?

1Q?  计算机的分类与应?
1.4.1 计算机的分类
按计机所处理对象的表CŞ式不同可?nbsp;    分成模拟计算Z数字计算ZcR?
计算机按其用途来分可以分成专用机和通用ZcR?br />其中Q通用计算机按其规模、性能和h格来分,又可分ؓ巨型机、大型机、小型机、工作站、微型机{多U类型?/p>

1.4.2 计算机应?计算Z息处理技术包括了对各U信息媒体的获取?表示、加工与表现Ҏ和技术,大致有以下几个方 面内容:
1Q语a与文字的处理?
2Q计机囑Ş学与数字图象处理?
3Q多媒体技术?br />4Q计机辅助技术?
5Q计机信息pȝ?
6Q计机控制?计算机应用技术的发展方向为集成化、网l化、智能化




bluesky 2006-02-16 10:10 发表评论
]]>
《微机原理与应用》考试大纲http://m.tkk7.com/bluesky/archive/2006/02/16/30910.htmlblueskyblueskyThu, 16 Feb 2006 01:38:00 GMThttp://m.tkk7.com/bluesky/archive/2006/02/16/30910.htmlhttp://m.tkk7.com/bluesky/comments/30910.htmlhttp://m.tkk7.com/bluesky/archive/2006/02/16/30910.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/30910.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/30910.html一、课E内?

 


W一?D

 


W一节:数据的表CZq算?/p>

W二节:微机的基本工作原理及l构?/p>

W三节:微处理器概述?/p>

W二?8086/8088微处理器

 


W一节:微处理器的内部结构及引脚功能?/p>

W二节:微机存储器组l及分段?/p>

W三节:ȝl构与ȝ周期?/p>

W三?8086/8088指opȝ

 


W一节:八种d方式Q立卛_址、直接寻址、寄存器d、寄存器间接d、寄存器相对d、基址变址d、基址变址且相对寻址、隐含寻址Q?/p>

W二节:六类指opȝQ数据传输指令、算术运指令、逻辑q算与移位指令、串操作指o?/p>

                     E序控制cL令、处理器控制指oQ?/p>

W四?nbsp;   汇编语言E序设计

 


W一节:汇编语言基本概念Q语句结构、伪指o、运符、宏指o、源E序l构{)

W二节:汇编语言E序设计ҎQ了解汇~语aE序设计的一般步?掌握序、分支、@环?/p>

                              子程序调用等汇编语言E序设计Ҏ。)

W五?nbsp;   存储?

 


W一节:存储器分cd主要性能指标?/p>

W二节:RAM、ROM介?/p>

W六?nbsp;  输入输出与中断系l?

 


W一节:接口概念、作用和~址Ҏ?/p>

W二节:输入输出传送方式(E序传送方式、中断方式、DMA方式Q?/p>

W三节:8086/8088中断pȝ?/p>


 


参考书目:

 


1Q李伯成Q侯伯亨Q张毅坤.《微型计机原理及应用?西安Q西安电子科技大学出版C? 1998q第1?

 



bluesky 2006-02-16 09:38 发表评论
]]>
OpenGLhttp://m.tkk7.com/bluesky/archive/2006/02/14/30641.htmlblueskyblueskyTue, 14 Feb 2006 09:23:00 GMThttp://m.tkk7.com/bluesky/archive/2006/02/14/30641.htmlhttp://m.tkk7.com/bluesky/comments/30641.htmlhttp://m.tkk7.com/bluesky/archive/2006/02/14/30641.html#Feedback1http://m.tkk7.com/bluesky/comments/commentRss/30641.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/30641.htmlmain.cpp
/**************************
 * Includes
 *
 **************************/

#include <windows.h>
#include <gl/gl.h>


/**************************
 * Function Declarations
 *
 **************************/

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);


/**************************
 * WinMain
 *
 **************************/

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;

    /* register window class */
    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 (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLSample";
    RegisterClass (&wc);

    /* create main window */
    hWnd = CreateWindow (
      "GLSample", "OpenGL Sample",
      WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
      0, 0, 256, 256,
      NULL, NULL, hInstance, NULL);

    /* enable OpenGL for the window */
    EnableOpenGL (hWnd, &hDC, &hRC);

    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
            /* OpenGL animation code goes here */

            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);
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL (hWnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow (hWnd);

    return msg.wParam;
}


/********************
 * Window Procedure
 *
 ********************/

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);
    }
}


/*******************
 * Enable OpenGL
 *
 *******************/

void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;

    /* get the device context (DC) */
    *hDC = GetDC (hWnd);

    /* set the pixel format for the DC */
    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);

    /* create and enable the render context (RC) */
    *hRC = wglCreateContext( *hDC );
    wglMakeCurrent( *hDC, *hRC );

}


/******************
 * Disable OpenGL
 *
 ******************/

void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
    wglMakeCurrent (NULL, NULL);
    wglDeleteContext (hRC);
    ReleaseDC (hWnd, hDC);
}



bluesky 2006-02-14 17:23 发表评论
]]>
[转蝲]C++: Hello, C++/CLI http://m.tkk7.com/bluesky/archive/2006/02/14/30638.htmlblueskyblueskyTue, 14 Feb 2006 09:02:00 GMThttp://m.tkk7.com/bluesky/archive/2006/02/14/30638.htmlhttp://m.tkk7.com/bluesky/comments/30638.htmlhttp://m.tkk7.com/bluesky/archive/2006/02/14/30638.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/30638.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/30638.html Contents


C++/CLI is a self-contained,  component-based dynamic programming language that, like C# or Java, is derived from C++. Unlike those languages, however, we have worked hard to integrate C++/CLI into ISO-C++, using the historical model of evolving the C/C++ programming language to support modern programming paradigms. You can say that C++/CLI is to C++ as C++ is to C. More generally, you can view the evolution leading to C++/CLI in the following historical context:

  • BCPL (Basic Computer Programming Language)
  • B (Ken Thompson, original UNIX work)
  • C (Dennis Ritchie, adding type and control structure to B)
  • C with Classes (~1979)
  • C84 (~1984)
  • Cfront, release E (~1984-to universities)
  • Cfront, release 1.0 (1985-to the world )?0th birthday
  • Multiple/Virtual Inheritance (MI) programming (~1988)
  • Generic Programming (~1991) (templates)
  • ANSI C++/ ISO-C++ (~1996)
  • Dynamic Component programming (~2005) (C++/CLI)


What is C++/CLI?

C++/CLI represents a tuple. C++ refers, of course, to the C++ programming language invented by Bjarne Stroustrup at Bell Laboratories. It supports a static object model that is optimized for the speed and size of its executables. However, it doesn't support run-time modification of the program other than heap allocation. It allows unlimited access to the underlying machine, but very little access to the types active in the running program and no real access to the associated infrastructure of that program. Herb Sutter, a former colleague of mine at Microsoft and the chief architect of C++/CLI, refers to C++ as a concrete language.

CLI refers to the Common Language Infrastructure, a multitiered architecture supporting a dynamic component programming model. In many ways, this represents a complete reversal of the C++ object model. A runtime software layer, the virtual execution system, runs between the program and the underlying operating system. Access to the underlying machine is fairly constrained. Access to the types active in the executing program and the associated program infrastructure—both as discovery and construction—is supported. The slash (/) represents a binding between C++ and the CLI. The details surrounding this binding make up the general topic of this column.

So, a first approximation of an answer to what is C++/CLI is that it is a binding of the static C++ object model to the dynamic component object model of the CLI. In short, it is how you do .NET programming using C++ rather than C# or Visual Basic]. Like C# and the CLI itself, C++/CLI is undergoing standardization under the European Computer Manufacturers Association (ECMA) and eventually under ISO.

The common language runtime (CLR) is the Microsoft version of the CLI that is specific to the Windows] operating system. Similarly, Visual C++] 2005 is the implementation of C++/CLI.

As a second approximation of an answer, I would say that C++/CLI integrates the .NET programming model within C++ in the same way as, back at Bell Laboratories, we integrated generic programming using templates within the then existing C++. In both of these cases your investment in an existing C++ codebase and in your existing C++ expertise are preserved. This was an essential baseline requirement of the design of C++/CLI.


Learning C++/CLI

There are three aspects in the design of a CLI language that hold true across all languages: a mapping of language-level syntax to the underlying Common Type System (CTS), the choice of a level of detail to expose the underlying CLI infrastructure to the manipulation of the programmer, and the choice of additional functionality to provide, beyond that supported directly by the CLI.

The first item is largely the same across all CLI languages. The second and third items are where one CLI language distinguishes itself from another. Depending on the kinds of problems you need to solve, you'll choose one or another language, or possibly combine multiple CLI languages. Learning C++/CLI involves understanding each of these aspects of its design.


Mapping C++/CLI to the CTS?

It is important when programming C++/CLI to learn the underlying CTS, which includes these three general class types:

  • The polymorphic reference type, which is what you use for all class inheritance.
  • The non-polymorphic value type, which is used for implementing concrete types requiring runtime efficiency, such as the numeric types.
  • The abstract interface type, which is used for defining a set of operations common to a set of either reference or value types that implement the interface.

This design aspect, the mapping of the CTS to a set of built-in language types, is common across all CLI languages although, of course, the syntax varies in each CLI language. So, for example, in C#, you would write

abstract class Shape { ... } // C#
to define an abstract Shape base class from which specific geometric objects are to be derived, while in C++/CLI you write
ref class Shape abstract { ... }; // C++/CLI
to indicate the exact same underlying CLI reference type. The two declarations are represented exactly the same way in the underlying IL. Similarly, in C#, you write
struct Point2D { ... } // C#
to define a concrete Point2D class, while in C++/CLI you write:
value class Point2D { ... }; // C++/CLI

The family of class types supported with C++/CLI represents an integration of the CTS with the native facilities, and that determines your choice of syntax. For example:

class native {};
value class V {};
ref class R {};
interface class I {};

The CTS also supports an enumeration class type that behaves somewhat differently from the native enumeration, and support is provided for both of those as well:

enum native { fail, pass }; 
enum class CLIEnum : char { fail, pass}; 
Similarly, the CTS supports its own array type that again behaves differently from the native array. And again Microsoft provides support for both:
int native[] = { 1,1,2,3,5,8 }; 
array<int>^ managed = { 1,1,2,3,5,8 };

No CLI language is closer to or more nearly a mapping to the underlying CTS than another. Rather, each CLI language represents a view into the underlying CTS object model.


CLI Level of Detail

The second design aspect that must be considered when designing a CLI language is the level of detail of the underlying CLI implementation model to incorporate into the language. What kind of problems will the language be tasked to solve? Does the language have the tools necessary to do this? Also, what sort of programmers is the language likely to attract?

Take, for example, the issue of value types occurring on the managed heap. Value types can find themselves on the managed heap in a number of circumstances:

  • Through implicit boxing, when an instance of a value type is assigned to an Object or when a virtual method is invoked through a value type that is not overridden.
  • When that value type is serving as a member of a reference class type.
  • When that value type is being stored as the element type of a CLI array.
Whether the programmer should be allowed to manipulate the address of a value type of this sort is a CLI language design consideration that must be addressed.


What Are the Issues?

Any object located on the managed heap is subject to relocation during the compaction phase of a sweep of the garbage collector. Any pointers to that object must be tracked and updated by the runtime; the programmer cannot manually track it herself. Therefore, if you were allowed to take the address of a value type that might be on the managed heap, there would need to be a tracking form of pointer in addition to the existing native pointer.

What are the trade-offs to consider? On the one hand, there's simplicity and safety. Directly introducing support in the language for either one or a family of tracking pointers makes it a more complicated language. By not supporting this, the available pool of programmers is expanded because less sophistication is required. In addition, allowing the programmer access to these ephemeral value types increases the possibility of programmer error—she may purposely or inadvertently do dangerous things to the memory. By not supporting tracking pointers, a potentially safer runtime environment is created.

On the other hand, efficiency and flexibility must be considered. Each time you assign the same Object with a value type, a new boxing of the value occurs. Allowing access to the boxed value type allows in-memory update, which may provide significant performance improvements. Without a form of tracking pointer, you cannot iterate over a CLI array using pointer arithmetic. This means that the CLI array cannot participate in the Standard Template Library (STL) iterator pattern and work with the generic algorithms. Allowing access to the boxed value type allows significant design flexibility.

Microsoft chose to provide a collection of addressing modes that handle value types on the managed heap in C++/CLI:

int ival = 1024;
int^ boxedi = ival; 

array<int>^ ia = gcnew array<int>{1,1,2,3,5,8};
interior_ptr<int> begin = &ia[0];

value struct smallInt { int m_ival; ... } si;
pin_ptr<int> ppi = &si.m_ival;

The typical C++/CLI developer is a sophisticated system programmer tasked with providing infrastructure and organizationally critical applications that serve as the foundation over which a business builds its future. She must address both scalability and performance concerns and must therefore have a system-level view into the underlying CLI. The level of detail of a CLI language reflects the face of its programmer.

Complexity is not in itself a negative quality. Human beings are more complicated than single-cell bacteria, and that is certainly not a bad thing. However, when the expression of a simple concept is made complicated, that is usually considered to be a bad thing. In C++/CLI, the CLI team has tried to provide an elegant way to express complex subject matter.


Additional Functionality

A third design aspect is a language-specific layer of functionality above and beyond what is directly supported by the CLI. This may require a mapping between the language-level support and the underlying implementation model of the CLI. In some cases, this just isn't possible because the language cannot intercede with the behavior of the CLI. One example of this is the virtual function resolution in the constructor and destructor of a base class. To reflect ISO-C++ semantics in this case would require a resetting of the virtual table within each base class constructor and destructor. This is not possible because virtual table handling is managed by the runtime and not by the individual language.

So this design aspect is a compromise between what would be preferable to do, and what is feasible. The three primary areas of additional functionality that are provided by C++/CLI are the following:

  • A form of Resource Acquisition is Initialization (RAII) for reference types, in particular, to provide an automated facility for what is referred to as deterministic finalization of garbage- collected types that hold scarce resources.
  • A form of deep-copy semantics associated with the C++ copy constructor and copy assignment operator; however, these semantics could not be extended to value types.
  • Direct support of C++ templates for CTS types in addition to the CLI generic mechanism. In addition, a verifiable version of the STL for CLI types is provided.

Let's look at a brief example: the issue of deterministic finalization. Before the memory associated with an object is reclaimed by the garbage collector, an associated Finalize method, if present, is invoked. You can think of this method as a kind of super-destructor since it is not tied to the program lifetime of the object. This is called finalization. The timing of just when or even whether a Finalize method is invoked is undefined. This is what is meant by nondeterministic finalization of the garbage collector.

Nondeterministic finalization works well with dynamic memory management. When available memory gets sufficiently scarce, the garbage collector kicks in and solves the problem. Nondeterministic finalization does not work well, however, when an object maintains a critical resource such as a database connection, a lock of some sort, or perhaps native heap memory. In this case, it would be great to release the resource as soon as it is no longer needed. The solution that is currently supported by the CLI is for a class to free the resources in its implementation of the Dispose method of the IDisposable interface. The problem here is that Dispose requires an explicit invocation, and therefore is not likely to be invoked.

A fundamental design pattern in C++ is the aforementioned Resource Acquisition is Initialization, which means that a class acquires resources within its constructor. Conversely, a class frees its resources within its destructor. This is managed automatically within the lifetime of the class object.

Here's what reference types should do in terms of the freeing of scarce resources:

  • Use the destructor to encapsulate the necessary code for the freeing of any resources associated with the class.
  • Have the destructor invoked automatically, tied with the lifetime of the class object.

The CLI has no notion of the class destructor for a reference type. So the destructor has to be mapped to something else in the underlying implementation. Internally, then, the compiler performs the following transformations:

  • The class has its base class list extended to inherit from the IDisposable interface.
  • The destructor is transformed into the Dispose method of IDisposable.

That represents half of the goal. A way to automate the invocation of the destructor is still needed. A special stack-based notation for a reference type is supported; that is, one in which its lifetime is associated within the scope of its declaration. Internally, the compiler transforms the notation to allocate the reference object on the managed heap. With the termination of the scope, the compiler inserts an invocation of the Dispose method—the user-defined destructor. Reclamation of the actual memory associated with the object remains under the control of the garbage collector. Figure 1 shows an example.

C++/CLI is not just an extension of C++ into the managed world. Rather, it represents a fully integrated programming paradigm similar in extent to the earlier integration of the multiple inheritance and generic programming paradigms into the language. I think the team has done an outstanding job.


So, What Did You Say About C++/CLI?

C++/CLI represents an integration of native and managed programming. In this iteration, that has been done through a kind of separate but equal community of source-level and binary elements, including Mixed mode (source-level mix of native and CTS types, plus a binary mix of native and CIL object files), Pure mode (source-level mix of native and CTS types, all compiled to CIL object files), Native classes (can hold CTS types through a special wrapper class only), and CTS classes (can hold native types only as pointers). Of course, the C++/CLI programmer can also choose to program in the CLI types alone, and in this way provide verifiable code that can be hosted, for example, as a stored procedure in SQL Server?/SUP> 2005.

So, returning to the question, what is C++/CLI? It is a first-class entry visa into the .NET programming model. With C++/CLI, there is a C++ migration path not just for the C++ source base but for C++ expertise as well. I find great satisfaction in that.


Send your questions and comments to  purecpp@microsoft.com.

Stanley B. Lippman began working on C++ with its inventor Bjarne Stroustrup back in 1984 within Bell Laboratories. Later, Stan worked in feature animation both at Disney and DreamWorks and served as a Software Technical Director on Fantasia 2000. He has since served as Distinguished Consultant with JPL and as an Architect with the Visual C++ team at Microsoft.
http://msdn.microsoft.com/msdnmag/issues/06/00/PureC/default.aspx

bluesky 2006-02-14 17:02 发表评论
]]>
C语言取得windows操作pȝ信息http://m.tkk7.com/bluesky/archive/2006/02/14/30610.htmlblueskyblueskyTue, 14 Feb 2006 06:53:00 GMThttp://m.tkk7.com/bluesky/archive/2006/02/14/30610.htmlhttp://m.tkk7.com/bluesky/comments/30610.htmlhttp://m.tkk7.com/bluesky/archive/2006/02/14/30610.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/30610.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/30610.html#include <windows.h>
#include <stdio.h>

#define BUFSIZE 80

BOOL GetOSVer(char *szOSName);

int main()
{
 char szname[MAX_PATH];
 memset(szname,0,MAX_PATH);

 BOOL bRet = GetOSVer(szname);

 printf("Your Os version is %s\n ",szname);

 return 0;
}

BOOL GetOSVer(char *szname)
{
   OSVERSIONINFOEX osvi;
   BOOL bOsVersionInfoEx;

   // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
   // If that fails, try using the OSVERSIONINFO structure.

   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

   if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
   {
      osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
      if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
         return FALSE;
   }

   switch (osvi.dwPlatformId)
   {
      // Test for the Windows NT product family.
      case VER_PLATFORM_WIN32_NT:

         // Test for the specific product family.
         if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
            strcpy(szname,"Microsoft Windows Server 2003 family, ");
  

         if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
            strcpy(szname,"Microsoft Windows XP ");

         if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
            strcpy(szname,"Microsoft Windows 2000 ");

         if ( osvi.dwMajorVersion <= 4 )
            strcpy(szname,"Microsoft Windows NT ");

         // Test for specific product on Windows NT 4.0 SP6 and later.
         if( bOsVersionInfoEx )
         {
            // Test for the workstation type.
            if ( osvi.wProductType == VER_NT_WORKSTATION )
            {
               if( osvi.dwMajorVersion == 4 )
                  strcat(szname, "Workstation 4.0 " );
               else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
                  strcat(szname, "Home Edition " );
               else
                  strcat(szname,  "Professional " );
            }
           
            // Test for the server type.
            else if ( osvi.wProductType == VER_NT_SERVER )
            {
               if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
               {
                  if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                     strcat(szname, "Datacenter Edition " );
                  else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                     strcat(szname, "Enterprise Edition " );
                  else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
                     strcat(szname, "Web Edition " );
                  else
                     strcat(szname, "Standard Edition " );
               }

               else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
               {
                  if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                     strcat(szname, "Datacenter Server " );
                  else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                     strcat(szname, "Advanced Server " );
                  else
                     strcat(szname, "Server " );
               }

               else  // Windows NT 4.0
               {
                  if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                     strcat(szname,"Server 4.0, Enterprise Edition " );
                  else
                     strcat(szname, "Server 4.0 " );
               }
            }
         }
         else  // Test for specific product on Windows NT 4.0 SP5 and earlier
         {
            HKEY hKey;
            char szProductType[BUFSIZE];
            DWORD dwBufLen=BUFSIZE;
            LONG lRet;

            lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
               "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
               0, KEY_QUERY_VALUE, &hKey );
            if( lRet != ERROR_SUCCESS )
               return FALSE;

            lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
               (LPBYTE) szProductType, &dwBufLen);
            if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
               return FALSE;

            RegCloseKey( hKey );

            if ( lstrcmpi( "WINNT", szProductType) == 0 )
               strcat(szname, "Workstation " );
            if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
               strcat(szname, "Server " );
            if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
               strcat(szname,"Advanced Server " );

            printf( "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion );
         }

      // Display service pack (if any) and build number.

         if( osvi.dwMajorVersion == 4 &&
             lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )
         {
            HKEY hKey;
            LONG lRet;

            // Test for SP6 versus SP6a.
            lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
               "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
               0, KEY_QUERY_VALUE, &hKey );
            if( lRet == ERROR_SUCCESS )
               printf( "Service Pack 6a (Build %d)\n", osvi.dwBuildNumber & 0xFFFF );        
            else // Windows NT 4.0 prior to SP6a
            {
               printf( "%s (Build %d)\n",
                  osvi.szCSDVersion,
                  osvi.dwBuildNumber & 0xFFFF);
            }

            RegCloseKey( hKey );
         }
         else // Windows NT 3.51 and earlier or Windows 2000 and later
         {
            printf( "%s (Build %d)\n",
               osvi.szCSDVersion,
               osvi.dwBuildNumber & 0xFFFF);
         }


         break;

      // Test for the Windows 95 product family.
      case VER_PLATFORM_WIN32_WINDOWS:

         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
         {
             strcpy(szname,"Microsoft Windows 95 ");
             if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
                strcat(szname,"OSR2 " );
         }

         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
         {
             strcpy(szname,"Microsoft Windows 98 ");
             if ( osvi.szCSDVersion[1] == 'A' )
                strcat(szname,"SE " );
         }

         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
         {
             strcpy(szname,"Microsoft Windows Millennium Edition\n");
         }
         break;

      case VER_PLATFORM_WIN32s:

         printf ("Microsoft Win32s\n");
         break;
   }
  // getchar();
   return TRUE;
}


 



bluesky 2006-02-14 14:53 发表评论
]]>
WindowsH体C语言http://m.tkk7.com/bluesky/archive/2006/02/14/30557.htmlblueskyblueskyTue, 14 Feb 2006 02:43:00 GMThttp://m.tkk7.com/bluesky/archive/2006/02/14/30557.htmlhttp://m.tkk7.com/bluesky/comments/30557.htmlhttp://m.tkk7.com/bluesky/archive/2006/02/14/30557.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/30557.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/30557.html#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND
, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName
[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance
,
                    HINSTANCE hPrevInstance
,
                    LPSTR lpszArgument
,
                    int nFunsterStil)

{
    HWND hwnd
;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance 
= hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon 
= LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground 
= (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class
, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 
0;

    /* The class is registered
, let's create the program*/
    hwnd 
= CreateWindowEx (
           
0,                   /* Extended possibilites for variation */
           szClassName
,         /* Classname */
           
"Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW
, /* default window */
           CW_USEDEFAULT
,       /* Windows decides the position */
           CW_USEDEFAULT
,       /* where the window ends up on the screen */
           
544,                 /* The programs width */
           
375,                 /* and height in pixels */
           HWND_DESKTOP
,        /* The window is a child-window to desktop */
           NULL
,                /* No menu */
           hThisInstance
,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           )
;

    /* Make the window visible on the screen */
    ShowWindow (hwnd
, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 
0 */
    while (GetMessage (&messages
, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages)
;
        /* Send message to WindowProcedure */
        DispatchMessage(&messages)
;
    }

    /* The program return-value is 
0 - The value that PostQuitMessage() gave */
    return messages.wParam
;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd
, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (
0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd
, message, wParam, lParam);
    }

    return 
0;
}


bluesky 2006-02-14 10:43 发表评论
]]>
水仙花问?/title><link>http://m.tkk7.com/bluesky/archive/2006/02/13/30480.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Mon, 13 Feb 2006 09:24:00 GMT</pubDate><guid>http://m.tkk7.com/bluesky/archive/2006/02/13/30480.html</guid><wfw:comment>http://m.tkk7.com/bluesky/comments/30480.html</wfw:comment><comments>http://m.tkk7.com/bluesky/archive/2006/02/13/30480.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/bluesky/comments/commentRss/30480.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/bluesky/services/trackbacks/30480.html</trackback:ping><description><![CDATA[解法1<BR> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">#include <stdio.h> <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>int main() <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>{ <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>int shu</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">bai</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">shi</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">ge</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000"> </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"> for (shu</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">shu<1000;shu++) </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"> { <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top> bai</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">shu/</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000"> </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"> shi</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">(shu-bai*</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #000000">)/</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000"> </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"> ge</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">shu-bai*</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #000000">-shi*</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000"> </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"> if(shu</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">(bai*bai*bai+shi*shi*shi+ge*ge*ge)) <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top> printf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">%d\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">shu)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000"> </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"> } <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>} </SPAN></DIV><BR>解法2<BR> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">int main(){ <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>int a</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">b</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">c</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">num</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000"> </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">for(a</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">a<10;a++){ </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">for(b</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">b<10;b++){ </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">for(c</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">c<10;c++){ </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">if(a*</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #000000">+b*</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">+c</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">(num</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">a*a*a+b*b*b+c*c*c)) <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>printf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">%d</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">num)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000"> </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">} <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>} <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>} <BR><IMG src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align=top>} </SPAN></DIV><BR><img src ="http://m.tkk7.com/bluesky/aggbug/30480.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/bluesky/" target="_blank">bluesky</a> 2006-02-13 17:24 <a href="http://m.tkk7.com/bluesky/archive/2006/02/13/30480.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C输出文g函数http://m.tkk7.com/bluesky/archive/2006/02/13/30479.htmlblueskyblueskyMon, 13 Feb 2006 09:16:00 GMThttp://m.tkk7.com/bluesky/archive/2006/02/13/30479.htmlhttp://m.tkk7.com/bluesky/comments/30479.htmlhttp://m.tkk7.com/bluesky/archive/2006/02/13/30479.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/30479.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/30479.htmlint main()
{
 FILE *fp;
  fp=fopen("fileout.txt","w+");
  fprintf(fp,"Helloworld");
  fputc('\n',fp);
  fclose(fp);
  return 0;
}

bluesky 2006-02-13 17:16 发表评论
]]>
GCC ?/title><link>http://m.tkk7.com/bluesky/archive/2006/02/13/30468.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Mon, 13 Feb 2006 08:19:00 GMT</pubDate><guid>http://m.tkk7.com/bluesky/archive/2006/02/13/30468.html</guid><wfw:comment>http://m.tkk7.com/bluesky/comments/30468.html</wfw:comment><comments>http://m.tkk7.com/bluesky/archive/2006/02/13/30468.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/bluesky/comments/commentRss/30468.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/bluesky/services/trackbacks/30468.html</trackback:ping><description><![CDATA[本节学习GNU推出的Linuxpȝ下C~译?---gccQ主要介l这U编译器的基本原理和使用ҎQ以及编译过E中所产生的错误的原因及对{?<br /><br />gcc?<br />Linuxpȝ下的gccQGNU C CompilerQ是GNU推出的功能强大、性能优越的多q_~译器,是GNU的代表作品之一。gcc是可以在多种体q_上编译出可执行程序的~译器,其执行效率与一般的~译器相比^均效率要?0%~30%?<br /><br />gcc~译器能C、C++语言源程序、汇E式化序和目标程序编译、连接成可执行文Ӟ如果没有l出可执行文件的名字Qgcc生成一个名为a.out的文件。在Linuxpȝ中,可执行文件没有统一的后~Q系l从文g的属性来区分可执行文件和不可执行文g。而gcc则通过后缀来区别输入文件的cdQ下面我们来介绍gcc所遵@的部分约定规则?<br /><br />.c为后~的文ӞC语言源代码文Ӟ <br /><br />.a为后~的文Ӟ是由目标文g构成的档案库文gQ?<br /><br />.CQ?cc?cxx 为后~的文Ӟ是C++源代码文Ӟ <br /><br />.h为后~的文Ӟ是程序所包含的头文gQ?<br /><br />.i 为后~的文Ӟ是已l预处理q的C源代码文Ӟ <br /><br />.ii为后~的文Ӟ是已l预处理q的C++源代码文Ӟ <br /><br />.m为后~的文Ӟ是Objective-C源代码文Ӟ <br /><br />.o为后~的文Ӟ是编译后的目标文Ӟ <br /><br />.s为后~的文Ӟ是汇~语a源代码文Ӟ <br /><br />.S为后~的文Ӟ是经q预~译的汇~语a源代码文件?<br /><br />gcc的执行过E?<br />虽然我们Ugcc是C语言的编译器Q但使用gcc由C语言源代码文件生成可执行文g的过E不仅仅是编译的q程Q而是要经历四个相互关联的步骤∉处理(也称预编译,Preprocessing)、编?Compilation)、汇~?Assembly)和连?Linking)?<br /><br />命ogcc首先调用cppq行预处理,在预处理q程中,Ҏ代码文g中的文g包含(include)、预~译语句(如宏定义define{?q行分析。接着调用cc1q行~译Q这个阶D|据输入文件生成以.o为后~的目标文件。汇~过E是针对汇编语言的步骤,调用asq行工作Q一般来Ԍ.S为后~的汇~语a源代码文件和汇编?s为后~的汇~语a文gl过预编译和汇编之后都生成以.o为后~的目标文件。当所有的目标文g都生成之后,gccp用ld来完成最后的关键性工作,q个阶段是q接。在q接阶段Q所有的目标文g被安排在可执行程序中的恰当的位置Q同Ӟ该程序所调用到的库函C从各自所在的档案库中q到合适的地方?<br /><br />gcc的基本用法和选项 <br />在用gcc~译器的时候,我们必须l出一pd必要的调用参数和文g名称。gcc~译器的调用参数大约?00多个Q其中多数参数我们可能根本就用不刎ͼq里只介l其中最基本、最常用的参数?<br /><br />gcc最基本的用法是∶gcc [options] [filenames] <br /><br />其中options是~译器所需要的参数Qfilenamesl出相关的文件名U?<br /><br />-cQ只~译Q不q接成ؓ可执行文Ӟ~译器只是由输入?c{源代码文g生成.o为后~的目标文Ӟ通常用于~译不包含主E序的子E序文g?<br /><br />-o output_filenameQ确定输出文件的名称为output_filenameQ同时这个名UC能和源文件同名。如果不l出q个选项Qgccq出预讄可执行文件a.out?<br /><br />-gQ生符可试工?GNU的gdb)所必要的符可讯,要想Ҏ代码q行调试Q我们就必须加入q个选项?<br /><br />-OQ对E序q行优化~译、连接,采用q个选项Q整个源代码会在~译、连接过E中q行优化处理Q这样生的可执行文件的执行效率可以提高Q但是,~译、连接的速度q应地要慢一些?<br /><br />-O2Q比-O更好的优化编译、连接,当然整个~译、连接过E会更慢?<br /><br />-IdirnameQ将dirname所指出的目录加入到E序头文件目录列表中Q是在预~译q程中用的参数。CE序中的头文件包含两U情况∶ <br /><br />A)#include <br /><br />B)#include “myinc.h” <br /><br />其中QAcM用尖括号(< >)QBcM用双引号(“ ”)。对于Ac,预处理程序cpp在系l预讑֌含文件目??usr/include)中搜ȝ应的文gQ而对于Bc,cpp在当前目录中搜寻头文Ӟq个选项的作用是告诉cppQ如果在当前目录中没有找到需要的文gQ就到指定的dirname目录中去L。在E序设计中,如果我们需要的q种包含文g分别分布在不同的目录中,需要逐个使用-I选项l出搜烦路径?<br /><br />-LdirnameQ将dirname所指出的目录加入到E序函数档案库文件的目录列表中,是在q接q程中用的参数。在预设状态下Q连接程序ld在系l的预设路径??usr/lib)L所需要的档案库文Ӟq个选项告诉q接E序Q首先到-L指定的目录中d找,然后到系l预设\径中LQ如果函数库存放在多个目录下Q就需要依ơ用这个选项Q给出相应的存放目录?<br /><br />-lnameQ在q接Ӟ装蝲名字?ldquo;libname.a”的函数库Q该函数库位于系l预讄目录或者由-L选项定的目录下。例如,-lm表示q接名ؓ“libm.a”的数学函数库?<br /><br />上面我们要介l了gcc~译器最常用的功能和主要参数选项Q更的资料可以参看Linuxpȝ的联机帮助?<br /><br />假定我们有一个程序名为test.c的C语言源代码文Ӟ要生成一个可执行文gQ最单的办法是?<br /><br />gcc test.c <br /><br />q时Q预~译、编译连接一ơ完成,生成一个系l预讄名ؓa.out的可执行文gQ对于稍为复杂的情况Q比如有多个源代码文件、需要连接档案库或者有其他比较特别的要求,pl定适当的调用选项参数。再看一个简单的例子?<br /><br />整个源代码程序由两个文gtestmain.c 和testsub.cl成Q程序中使用了系l提供的数学库,同时希望l出的可执行文g为testQ这时的~译命o可以是∶ <br /><br />gcc testmain.c testsub.c □lm □o test <br /><br />其中Q?lm表示q接pȝ的数学库libm.aQ这个过E可以用?2-1框图描述?<br /><br /><br />gcc的错误类型及对策 <br />gcc~译器如果发现源E序中有错误Q就无法l箋q行Q也无法生成最l的可执行文件。ؓ了便于修改,gccl出错误资讯Q我们必dq些错误资讯逐个q行分析、处理,q修改相应的语言Q才能保证源代码的正编译连接。gccl出的错误资讯一般可以分为四大类Q下面我们分别讨论其产生的原因和对策?<br /><br />W一cZC语法错误 <br />错误资讯∶文件source.c中第n行有语法错误(syntex errror)。这U类型的错误Q一般都是C语言的语法错误,应该仔细查源代码文g中第n行及该行之前的程序,有时也需要对该文件所包含的头文gq行查。有些情况下Q一个很单的语法错误Qgcc会给Z大堆错误Q我们最主要的是要保持清醒的头脑Q不要被其吓倒,必要的时候再参考一下C语言的基本教材?<br /><br />W二cZ头文仉?<br />错误资讯∶找不到头文件head.h(Can not find include file head.h)。这c错误是源代码文件中的包含头文g有问题,可能的原因有头文件名错误、指定的头文件所在目录名错误{,也可能是错误C用了双引号和括受?<br /><br />W三cZ档案库错?<br />错误资讯∶连接程序找不到所需的函数库Q例如∶ <br /><br />ld: -lm: No such file or directory <br /><br />q类错误是与目标文g相连接的函数库有错误Q可能的原因是函数库名错误、指定的函数库所在目录名U错误等Q检查的Ҏ是用find命o在可能的目录中寻扄应的函数库名Q确定档案库及目录的名称q修改程序中及编译选项中的名称?<br /><br />W四cZ未定义符?<br />错误资讯∶有未定义的W号(Undefined symbol)。这c错误是在连接过E中出现的,可能有两U原因∶一是用者自己定义的函数或者全局变量所在源代码文gQ没有被~译、连接,或者干脆还没有定义Q这需要用者根据实际情况修ҎE序Q给出全局变量或者函数的定义体;二是未定义的W号是一个标准的库函敎ͼ在源E序中用了该库函数Q而连接过E中q没有给定相应的函数库的名称Q或者是该档案库的目录名U有问题Q这旉要用档案库l护命oar查我们需要的库函数到底位于哪一个函数库中,定之后Q修改gccq接选项中的-l?LV?br /><br />排除~译、连接过E中的错误,应该说这只是E序设计中最单、最基本的一个步骤,可以说只是开了个头。这个过E中的错误,只是我们在用C语言描述一个算法中所产生的错误,是比较容易排除的。我们写一个程序,到编译、连接通过为止Q应该说刚刚开始,E序在运行过E中所出现的问题,是算法设计有问题Q说得更玄点是对问题的认识和理解不够Q还需要更加深入地试、调试和修改。一个程序,Eؓ复杂的程序,往往要经q多ơ的~译、连接和试、修攏V下面我们学习的E序l护、调试工具和版本l护是在程序调试、测试过E中使用的,用来解决调测阶段所出现的问?br /><br /><a >http://www.study888.com/computer/pro/c/jiqiao/200506/37410_2.html</a><img src ="http://m.tkk7.com/bluesky/aggbug/30468.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/bluesky/" target="_blank">bluesky</a> 2006-02-13 16:19 <a href="http://m.tkk7.com/bluesky/archive/2006/02/13/30468.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GCC介绍http://m.tkk7.com/bluesky/archive/2006/02/13/30466.htmlblueskyblueskyMon, 13 Feb 2006 08:12:00 GMThttp://m.tkk7.com/bluesky/archive/2006/02/13/30466.htmlhttp://m.tkk7.com/bluesky/comments/30466.htmlhttp://m.tkk7.com/bluesky/archive/2006/02/13/30466.html#Feedback0http://m.tkk7.com/bluesky/comments/commentRss/30466.htmlhttp://m.tkk7.com/bluesky/services/trackbacks/30466.html在ؓLinux开发应用程序时,l大多数情况下用的都是C语言,因此几乎每一位LinuxE序员面临的首要问题都是如何

灉|q用C~译?目前Linux下最常用的C语言~译器是GCC(GNU Compiler Collection),它是GNU目中符合ANSI C

标准的编译系l?能够~译用C、C++和Object C{语a~写的程?GCC不仅功能非常强大,l构也异常灵z?最值得U?/p>

道的一点就是它可以通过不同的前端模块来支持各种语言,如Java、Fortran、Pascal、Modula-3和Ada{?

开放、自由和灉|是Linux的魅力所?而这一点在GCC上的体现是E序员通过它能够更好地控制整个~译q程.?/p>

使用GCC~译E序?~译q程可以被细分ؓ四个阶段:

?预处?Pre-Processing)

?~译(Compiling)

?汇编(Assembling)

?链接(Linking)

LinuxE序员可以根据自q需要让GCC在编译的M阶段l束,以便查或使用~译器在该阶D늚输出信息,或者对

最后生成的二进制文件进行控?以便通过加入不同数量和种cȝ调试代码来ؓ今后的调试做好准?和其它常用的

~译器一?GCC也提供了灉|而强大的代码优化功能,利用它可以生成执行效率更高的代码.

GCC提供?0多条警告信息和三个警告?使用它们有助于增强程序的E_性和可移植?此外,GCCq对标准的C?/p>

C++语言q行了大量的扩展,提高E序的执行效?有助于编译器q行代码优化,能够减轻~程的工作量.

GCCh

在学习用GCC之前,下面的这个例子能够帮助用戯速理解GCC的工作原?q将其立卌用到实际的项目开发中?

首先用熟悉的~辑器输入清?所C的代码:

清单1:hello.c

#include <stdio.h>
int main(void)
{
 printf (Hello world, Linux programming!\\n);
 return 0;
}
 


然后执行下面的命令编译和q行q段E序:

# gcc hello.c -o hello
# ./hello
Hello world, Linux programming!
 


从程序员的角度看,只需单地执行一条GCC命o可以了,但从~译器的角度来看,却需要完成一pd非常J杂的工

?首先,GCC需要调用预处理E序cpp,由它负责展开在源文g中定义的?q向其中插入“#include”语句所包含?/p>

内容Q接着,GCC会调用ccl和as处理后的源代码~译成目标代码;最?GCC会调用链接程序ld,把生成的目标代码

链接成一个可执行E序.

Z更好地理解GCC的工作过E?可以把上q编译过E分成几个步骤单独进?q观察每步的q行l果.W一步是q行

预编?使用-E参数可以让GCC在预处理l束后停止编译过E?

#  gcc -E hello.c -o hello.i
 


此时若查看hello.cpp文g中的内容,会发现stdio.h的内容确实都插到文g里去?而其它应当被预处理的宏定义也

都做了相应的处理.下一步是hello.i~译为目标代?q可以通过使用-c参数来完?

#  gcc -c hello.i -o hello.o
 


GCC默认?i文g看成是预处理后的C语言源代?因此上述命o自动蟩q预处理步骤而开始执行编译过E?也可?/p>

使用-x参数让GCC从指定的步骤开始编?最后一步是生成的目标文g链接成可执行文g:

#  gcc hello.o -o hello
 


在采用模块化的设计思想q行软g开发时,通常整个E序是由多个源文件组成的,相应CŞ成了多个~译单元,?/p>

用GCC能够很好地管理这些编译单?假设有一个由foo1.c和foo2.c两个源文件组成的E序,Z对它们进行编?q?/p>

最l生成可执行E序foo,可以使用下面q条命o:

#  gcc foo1.c foo2.c -o foo
 


如果同时处理的文件不止一?GCC仍然会按照预处理、编译和链接的过E依ơ进?如果qh,上面q条命o?/p>

致相当于依次执行如下三条命o:

# gcc -c foo1.c -o foo1.o
# gcc -c foo2.c -o foo2.o
# gcc foo1.o foo2.o -o foo
 


在编译一个包含许多源文g的工E时,若只用一条GCC命o来完成编译是非常费旉?假设目中有100个源文g

需要编?q且每个源文件中都包?0000行代?如果像上面那样仅用一条GCC命o来完成编译工?那么GCC需要将

每个源文仉重新~译一?然后再全部连接v?很显?q样费的时间相当多,其是当用户只是修改了其中某

一个文件的时?完全没有必要每个文仉重新~译一?因ؓ很多已经生成的目标文件是不会改变?要解册?/p>

问题,关键是要灉|q用GCC,同时q要借助像Makeq样的工?

警告提示功能

GCC包含完整的出错检查和警告提示功能,它们可以帮助LinuxE序员写出更加专业和优美的代?先来读读清单2所C?/p>

的程?q段代码写得很糟p?仔细查一下不难挑出很多毛?

◆main函数的返回D声明为void,但实际上应该是intQ?

◆用了GNU语法扩展,即用long long来声?4位整?不符合ANSI/ISO C语言标准Q?

◆main函数在终止前没有调用return语句.

清单2:illcode.c

#include <stdio.h>
void main(void)
{
  long long int var = 1;
  printf(It is not standard C code!\\n);
}
 


下面来看看GCC是如何帮助程序员来发现这些错误的.当GCC在编译不W合ANSI/ISO C语言标准的源代码?如果加上

?pedantic选项,那么使用了扩展语法的地方生相应的警告信息:

# gcc -pedantic illcode.c -o illcode
illcode.c: In function `main':
illcode.c:9: ISO C89 does not support `long long'
illcode.c:8: return type of `main' is not `int'
 


需要注意的?-pedantic~译选项q不能保证被~译E序与ANSI/ISO C标准的完全兼?它仅仅只能用来帮助Linux

E序员离q个目标来近.或者换句话?-pedantic选项能够帮助E序员发C些不W合ANSI/ISO C标准的代?

但不是全?事实上只有ANSI/ISO C语言标准中要求进行编译器诊断的那些情?才有可能被GCC发现q提?

除了-pedantic之外,GCCq有一些其它编译选项也能够生有用的警告信息.q些选项大多?W开?其中最有h值的

当数-Wall?使用它能够GCC产生可能多的警告信?

# gcc -Wall illcode.c -o illcode
illcode.c:8: warning: return type of `main' is not `int'
illcode.c: In function `main':
illcode.c:9: warning: unused variable `var'
 


GCCl出的警告信息虽然从严格意义上说不能作是错?但却很可能成为错误的栖n之所.一个优U的LinuxE序?/p>

应该量避免产生警告信息,使自q代码始终保持z、优和健壮的特?

在处理警告方?另一个常用的~译选项?Werror,它要求GCC所有的警告当成错误q行处理,q在使用自动~译?/p>

?如Make{?旉常有?如果~译时带?Werror选项,那么GCC会在所有生警告的地方停止~译,qɽE序员对?/p>

q代码q行修改.只有当相应的警告信息消除?才可能将~译q程l箋朝前推进.执行情况如下:

# gcc -Wall -Werror illcode.c -o illcode
cc1: warnings being treated as errors
illcode.c:8: warning: return type of `main' is not `int'
illcode.c: In function `main':
illcode.c:9: warning: unused variable `var'
 


对LinuxE序员来?GCCl出的警告信息是很有价值的,它们不仅可以帮助E序员写出更加健壮的E序,而且q是跟踪

和调试程序的有力工具.在用GCC~译源代码时始终带上-Wall选项,q把它逐渐培养成ؓ一U习?q对扑և常见

的隐式编E错误很有帮?

库依?

在Linux下开发Y件时,完全不用第三方函数库的情况是比较少见的,通常来讲都需要借助一个或多个函数库的支持

才能够完成相应的功能.从程序员的角度看,函数库实际上是一些头文g(.h)和库文g(.so或?a)的集?虽然

Linux下的大多数函数都默认头文g攑ֈ/usr/include/目录?而库文g则放?usr/lib/目录?但ƈ不是所有的

情况都是q样.正因如此,GCC在编译时必须有自q办法来查找所需要的头文件和库文?

GCC采用搜烦目录的办法来查找所需要的文g,-I选项可以向GCC的头文g搜烦路径中添加新的目?例如,如果

?home/xiaowp/include/目录下有~译时所需要的头文?Z让GCC能够利地找到它?可以?I选项:

# gcc foo.c -I /home/xiaowp/include -o foo
 


同样,如果使用了不在标准位|的库文?那么可以通过-L选项向GCC的库文g搜烦路径中添加新的目?例如,如果?/p>

/home/xiaowp/lib/目录下有链接时所需要的库文件libfoo.so,Z让GCC能够利地找到它,可以使用下面的命?

# gcc foo.c -L /home/xiaowp/lib -lfoo -o foo
 


值得好好解释一下的?l选项,它指CGCC去连接库文glibfoo.so.Linux下的库文件在命名时有一个约?那就是应

该以lib三个字母开?׃所有的库文仉遵@了同L规范,因此在用-l选项指定链接的库文g名时可以省去lib

三个字母,也就是说GCC在对-lfooq行处理?会自动去链接名ؓlibfoo.so的文?

Linux下的库文件分Z大类分别是动态链接库(通常?sol尾)和静态链接库(通常?al尾),两者的差别仅在E序

执行时所需的代码是在运行时动态加载的,q是在编译时静态加载的.默认情况?GCC在链接时优先使用动态链接库,

只有当动态链接库不存在时才考虑使用静态链接库,如果需要的话可以在~译时加?static选项,强制使用静态链?/p>

?例如,如果?home/xiaowp/lib/目录下有链接时所需要的库文件libfoo.so和libfoo.a,Z让GCC在链接时只用

到静态链接库,可以使用下面的命?

# gcc foo.c -L /home/xiaowp/lib -static -lfoo -o foo
 
代码优化

代码优化指的是编译器通过分析源代?扑և其中未辑ֈ最优的部分,然后对其重新q行l合,目的是改善程序的?/p>

行性能.GCC提供的代码优化功能非常强?它通过~译选项-On来控制优化代码的生成,其中n是一个代表优化别的

整数.对于不同版本的GCC来讲,n的取D围及其对应的优化效果可能q不完全相同,比较典型的范围是?变化??/p>

3.

~译时用选项-O可以告诉GCC同时减小代码的长度和执行旉,其效果等价于-O1.在这一U别上能够进行的优化c?/p>

型虽然取决于目标处理?但一般都会包括线E蟩?Thread Jump)和gq退?Deferred Stack Pops)两种优化.?/p>

?O2告诉GCC除了完成所?O1U别的优化之?同时q要q行一些额外的调整工作,如处理器指o调度{?选项-O3?/p>

除了完成所?O2U别的优化之?q包括@环展开和其它一些与处理器特性相关的优化工作.通常来说,数字大?/p>

化的{񔭑高,同时也就意味着E序的运行速度快.许多LinuxE序员都喜欢使用-O2选项,因ؓ它在优化长度、编?/p>

旉和代码大之?取得了一个比较理想的q?

下面通过具体实例来感受一下GCC的代码优化功?所用程序如清单3所C?

清单3:optimize.c

#include <stdio.h>
int main(void)
{
  double counter;
  double result;
  double temp;
  for (counter = 0;
   counter < 2000.0 * 2000.0 * 2000.0  / 20.0 + 2020;
   counter += (5 - 1) / 4) {
    temp = counter / 1979;
    result  = counter;   
  }
  printf(Result is %lf\\n, result);
  return 0;
}
 


首先不加M优化选项q行~译:

# gcc -Wall optimize.c -o optimize
 


借助Linux提供的time命o,可以大致l计E序在运行时所需要的旉:

# time ./optimize
Result is 400002019.000000
real    0m14.942s
user    0m14.940s
sys     0m0.000s
 


接下M用优化选项来对代码q行优化处理:

# gcc -Wall -O optimize.c -o optimize
 


在同L条g下再ơ测试一下运行时?

# time ./optimize
Result is 400002019.000000
real    0m3.256s
user    0m3.240s
sys     0m0.000s
 


Ҏ两次执行的输出结果不隄?E序的性能的确得到了很大幅度的改善,由原来的14U羃短到?U?q个例子?/p>

专门针对GCC的优化功能而设计的,因此优化前后E序的执行速度发生了很大的改变.管GCC的代码优化功能非常强

?但作Z名优U的LinuxE序?首先q是要力求能够手工编写出高质量的代码.如果~写的代码简?q且逻辑?/p>

?~译器就不会做更多的工作,甚至Ҏ用不着优化.

优化虽然能够l程序带来更好的执行性能,但在如下一些场合中应该避免优化代码:

?E序开发的时?优化{񔭑高,消耗在~译上的旉p?因此在开发的时候最好不要用优化选项,只有到Y

件发行或开发结束的时?才考虑Ҏl生成的代码q行优化.

?资源受限的时?一些优化选项会增加可执行代码的体U?如果E序在运行时能够甌到的内存资源非常紧张(?/p>

一些实时嵌入式讑֤),那就不要对代码进行优?因ؓp带来的负面媄响可能会产生非常严重的后?

?跟踪调试的时?在对代码q行优化的时?某些代码可能会被删除或改?或者ؓ了取得更佳的性能而进行重l?

从而跟踪和调试变得异常困?

调试

一个功能强大的调试器不仅ؓE序员提供了跟踪E序执行的手D?而且q可以帮助程序员扑ֈ解决问题的方?对于

LinuxE序员来?GDB(GNU Debugger)通过与GCC的配合?为基于Linux的Y件开发提供了一个完善的调试环境.

默认情况?GCC在编译时不会调试符h入到生成的二q制代码?因ؓq样会增加可执行文g的大?如果需?/p>

在编译时生成调试W号信息,可以使用GCC?g或?ggdb选项.GCC在生调试符h,同样采用了分U的思\,开发h

员可以通过?g选项后附加数???来指定在代码中加入调试信息的多少.默认的别是2(-g2),此时产生的调?/p>

信息包括扩展的符可、行受局部或外部变量信息.U别3(-g3)包含U别2中的所有调试信?以及源代码中定义?/p>

?U别1(-g1)不包含局部变量和与行h关的调试信息,因此只能够用于回溯跟t和堆栈转储之用.回溯跟踪指的?/p>

监视E序在运行过E中的函数调用历?堆栈转储则是一U以原始的十六进制格式保存程序执行环境的Ҏ,两者都

是经常用到的调试手段.

GCC产生的调试符号具有普遍的适应?可以被许多调试器加以利用,但如果用的是GDB,那么q可以通过-ggdb选项

在生成的二进制代码中包含GDB专用的调试信?q种做法的优Ҏ可以方便GDB的调试工?但缺Ҏ可能D其它

调试?如DBX)无法q行正常的调?选项-ggdb能够接受的调试别和-g是完全一L,它们对输出的调试W号有着

相同的媄?

需要注意的?使用M一个调试选项都会使最l生成的二进制文件的大小急剧增加,同时增加E序在执行时的开销,

因此调试选项通常仅在软g的开发和调试阶段使用.调试选项对生成代码大的影响从下面的Ҏq程中可以看出来

:

# gcc optimize.c -o optimize
# ls optimize -l
-rwxrwxr-x  1 xiaowp   xiaowp  11649 Nov 20 08:53 optimize  (未加调试选项)
# gcc -g optimize.c -o optimize
# ls optimize -l
-rwxrwxr-x  1 xiaowp   xiaowp  15889 Nov 20 08:54 optimize  (加入调试选项)
 


虽然调试选项会增加文件的大小,但事实上Linux中的许多软g在测试版本甚xl发行版本中仍然使用了调试选项

来进行编?q样做的目的是鼓q户在发现问题时自己动手解?是Linux的一个显著特?

试编译代?Compiling Code for Debugging)
Z?gdb 正常工作, 你必M你的E序在编译时包含调试信息. 调试信息包含你程序里的每个变量的cd和在?/p>

执行文g里的地址映射以及源代码的行号. gdb 利用q些信息使源代码和机器码相关?
◆在~译时用 -g 选项打开调试选项.
 

gdb 基本命o
     gdb 支持很多的命令你能实现不同的功? q些命o从简单的文g装入到允怽查所调用的堆栈内容的?/p>

杂命? ?7.1列出了你在用 gdb 调试时会用到的一些命? 想了?gdb 的详l用请参?gdb 的指南页.
  ?27.1. 基本 gdb 命o.
?nbsp;  ??nbsp; q?
file 装入惌调试的可执行文g.
kill l止正在调试的程?
list 列出产生执行文g的源代码的一部分.
next 执行一行源代码但不q入函数内部.
step 执行一行源代码而且q入函数内部.
run 执行当前被调试的E序
quit l止 gdb
watch 使你能监视一个变量的D不它何时被改?
break 在代码里讄断点, q将使程序执行到q里时被挂v.
make 使你能不退?gdb 可以重C生可执行文g.
shell 使你能不d gdb 执?UNIX shell 命o. 

gdb 支持很多?UNIX shell E序一L命o~辑特征. 你能象在 bash ?tcsh里那h Tab 键让gdb 帮你补齐

一个唯一的命? 如果不唯一的话 gdb 会列出所有匹配的命o. 你也能用光标键上下翻动历史命?


下面q是通过一个具体的实例说明如何利用调试W号来分析错?所用程序见清单4所C?

清单4:crash.c

#include <stdio.h>
int main(void)
{
  int input =0;
  printf(Input an integer:);
  scanf(%d, input);
  printf(The integer you input is %d\\n, input);
  return 0;
}
 


~译q运行上qC?会生一个严重的D错?Segmentation fault)如下:

# gcc -g crash.c -o crash
# ./crash
Input an integer:10
Segmentation fault
 


Z更快速地发现错误所?可以使用GDBq行跟踪调试,Ҏ如下:

# gdb crash
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
……
(gdb)
 


当GDB提示W出现的时?表明GDB已经做好准备q行调试?现在可以通过run命o让程序开始在GDB的监控下q行:

(gdb) run
Starting program: /home/xiaowp/thesis/gcc/code/crash
Input an integer:10

Program received signal SIGSEGV, Segmentation fault.
0x4008576b in _IO_vfscanf_internal () from /lib/libc.so.6
 


仔细分析一下GDBl出的输出结果不隄?E序是由于段错误而导致异怸止的,说明内存操作Z问题,具体发生

问题的地Ҏ在调用_IO_vfscanf_internal ( )的时?Z得到更加有h值的信息,可以使用GDB提供的回溯跟t命

令backtrace,执行l果如下:

(gdb) backtrace
#0  0x4008576b in _IO_vfscanf_internal () from /lib/libc.so.6
#1  0xbffff0c0 in ?? ()
#2  0x4008e0ba in scanf () from /lib/libc.so.6
#3  0x08048393 in main () at crash.c:11
#4  0x40042917 in __libc_start_main () from /lib/libc.so.6
 


跌输出l果中的前面三行,从输出结果的W四行中不难看出,GDB已经错误定位到crash.c中的W?1行了.现在仔细

查一?

(gdb) frame 3
#3  0x08048393 in main () at crash.c:11
11       scanf(%d, input);
 


使用GDB提供的frame命o可以定位到发生错误的代码D?该命令后面跟着的数值可以在backtrace命o输出l果中的

行首扑ֈ.现在已经发现错误所在了,应该?

scanf(%d, input);
改ؓ
scanf(%d, &input);
 


完成后就可以退出GDB?命o如下:

(gdb) quit
 


GDB的功能远q不止如?它还可以单步跟踪E序、检查内存变量和讄断点{?

调试时可能会需要用到编译器产生的中间结?q时可以使用-save-temps选项,让GCC预处理代码、汇~代码和?/p>

标代码都作ؓ文g保存h.如果x查生成的代码是否能够通过手工调整的办法来提高执行性能,在编译过E中?/p>

成的中间文g会很有帮助,具体情况如下:

# gcc -save-temps foo.c -o foo
# ls foo*
foo  foo.c  foo.i  foo.s
 


GCC支持的其它调试选项q包?p?pg,它们会将剖析(Profiling)信息加入到最l生成的二进制代码中.剖析信息?/p>

于找出程序的性能瓉很有帮助,是协助LinuxE序员开发出高性能E序的有力工?在编译时加入-p选项会在生成?/p>

代码中加入通用剖析工具(Prof)能够识别的统计信??pg选项则生成只有GNU剖析工具(Gprof)才能识别的统计信

?

最后提醒一?虽然GCC允许在优化的同时加入调试W号信息,但优化后的代码对于调试本w而言是一个很大的挑战

.代码在经q优化之?在源E序中声明和使用的变量很可能不再使用,控制也可能会突然蟩转到意外的地?循环

语句有可能因为@环展开而变得到处都?所有这些对调试来讲都将是一场噩?在调试的时候最好不使用M

优化选项,只有当程序在最l发行的时候才考虑对其q行优化.


上次的培训园C介绍了GCC的编译过E、警告提C功能、库依赖、代码优化和E序调试六个斚w的内?q期是最

后的一部分内容.

加?

在将源代码变成可执行文g的过E中,需要经q许多中间步?包含预处理、编译、汇~和q接.q些q程实际上是?/p>

不同的程序负责完成的.大多数情况下GCC可以为LinuxE序员完成所有的后台工作,自动调用相应E序q行处理.

q样做有一个很明显的缺?是GCC在处理每一个源文g?最l都需要生成好几个临时文g才能完成相应的工?

从而无形中D处理速度变慢.例如,GCC在处理一个源文g?可能需要一个时文件来保存预处理的输出、一个

时文件来保存~译器的输出、一个时文件来保存汇编器的输出,而读写这些时文件显焉要耗费一定的旉.?/p>

软g目变得非常庞大的时?p在这上面的代价可能会变得很沉?

解决的办法是,使用Linux提供的一U更加高效的通信方式—道.它可以用来同时连接两个程?其中一个程序的?/p>

出将被直接作为另一个程序的输入,q样可以避免用时文?但编译时却需要消耗更多的内存.

在编译过E中使用道是由GCC?pipe选项军_?下面的这条命令就是借助GCC的管道功能来提高~译速度?

# gcc -pipe foo.c -o foo
 


在编译小型工E时使用道,~译旉上的差异可能q不是很明显,但在源代码非常多的大型工E中,差异变得非?/p>

明显.


文g扩展?

在用GCC的过E中,用户对一些常用的扩展名一定要熟悉,q知道其含义.Z方便大家学习使用GCC,在此这些扩

展名|列如下:

.c C原始E序Q?

.C C++原始E序Q?

.cc C++原始E序Q?

.cxx C++原始E序Q?

.m Objective-C原始E序Q?

.i 已经q预处理的C原始E序Q?

.ii 已经q预处理之C++原始E序Q?

.s l合语言原始E序Q?

.S l合语言原始E序Q?

.h 预处理文?标头文g)Q?

.o 目标文gQ?

.a 存档文g.

GCC常用选项

GCC作ؓLinux下C/C++重要的编译环?功能强大,~译选项J多.Z方便大家日后~译方便,在此常用的选项及说

明罗列出来如?

-c 通知GCC取消链接步骤,即编译源码ƈ在最后生成目标文Ӟ

-Dmacro 定义指定的宏,使它能够通过源码中的#ifdefq行验;

-E 不经q编译预处理E序的输输送至标准输出Q?

-g3 获得有关调试E序的详l信?它不能与-o选项联合使用Q?

-Idirectory 在包含文件搜索\径的L处添加指定目录;

-llibrary 提示链接E序在创建最l可执行文g时包含指定的库;

-O?O2?O3 优化状态打开,该选项不能?g选项联合使用Q?

-S 要求~译E序生成来自源代码的汇编E序输出Q?

-v 启动所有警报;

-Wall 在发生警报时取消~译操作,卛_警报看作是错误;

-Werror 在发生警报时取消~译操作,x报警当作是错误;

-w 止所有的报警.

GCC是在Linux下开发程序时必须掌握的工具之一.本文对GCC做了一个简要的介绍,主要讲述了如何用GCC~译E序

、生警告信息、调试程序和加快GCC的编译速度.Ҏ有希望早日跨入Linux开发者行列的人来?GCC是成ؓ一?/p>

优秀的LinuxE序员的赯U?

http://delia.org.ru/ArticleView/2005-9-7/Article_View_131482.Htm



bluesky 2006-02-13 16:12 发表评论
]]>
վ֩ģ壺 ޾Ʒ91רֻ| ߹ۿƵ| ձһƬ2019| ޹Ů߹ۿ| 99reƵ| þþþAVվ| ҹ뾫Ʒѿ| avһ| þ91Ƶۿվ| þþ޾ƷƵ| 99þƷƵ77| þۺɫHEZYO| Ƶ߹ۿ| ޸߹ۿ| ձ| ޾ƷþþþAVƬ| ƷƷþһʽ | 99޾Ʒһ| ޾Ʒѿ| һ| պƵ| պĻ| ƵƵ| պaëƬa| 99þۺϾƷ| ɫ޾ƷĻ| þþþþùƷ| ɫɫwww| ޾Ʒ岻| һƵѸ| ޴˽| ˳վ߲| þĻƵ| ŷɫͼƬ| Ļ߹ۿ| av߿վ| ɫַ| Ƶһ߹ۿ| ޳avƬһ| ƷƵѹۿ| һƵ|