Suzuki's C / C++ Builder / Delphi Page
The Home Page on the Net Tips for Programming
L a n g u a g e  a c t u a l l y  m a t t e r s  a n d  m u c h  i f  y o u  c a r e !

1 Tips for C++ Builder

  • ExtractFileDrive(a) results in c:
  • ExtractFileDir(a) results in c:\temp_c\bakfiles
  • ExtractFilePath(a) results in c:\temp_c\bakfiles\
  • ExtractFileExt(a) results in .bak

  1. Put a WAV file into an RC file like the following: 101 RCDATA "autocor.wav"

  2. And in the source CPP file:
    HRSRC hrsrc = ::FindResourceEx(HInstance , RT_RCDATA , "#101" ,

    TCHAR* Fpautocor_wave = (TCHAR *)LockResource(LoadResource (HInstance , hrsrc));

    PlaySound(Fpautocor_wave, NULL, SND_ASYNC| SND_MEMORY);


1 Tips for C/C++

Reserved C(bold)/C++ Key Words
asm auto bool break case catch char class const const_cast continue default delete do double dynamic_cast else enum extern false float for friend goto if inline int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid union unsigned virtual void volatile wchar_t while

The maximum length of a variable name: 31 characters.

C Data Types

Key word Bytes Range
char 1 -128 ~ 127
int 2( or 4) -32768 ~ 32767
short 2( or 4) -32768 ~ 32767
long 4 -2147483648 ~ 2147483647
unsigned char 1 0 ~ 255
unsigned int 2( or 4) 0 ~ 65535
unsigned short 2( or 4) 0 ~ 65535
unsigned long 4 0 ~ 4294967295
float 4 1.2E-38 ~ 3.4E38
double 8 2.2E-308 ~ 1.8E308

Operator Precedence

Arithmatic Operator Relative Precedence
++ -- 1
* / % 2
+ - 3
Relational Operator Relative Precedence
< <= > >= 1
!= == 2

printf conversion specifiers

Specifier Meaning Conversion Type
%c single character char
%d signed decimal integer int, short
%ld signed long decimal integer long
%f decimal floating-point number float, double   (eg: %.2f ->  32.00)
%s character string char array
%u unsigned decimal integer unsigned int, unsigned short
%lu unsigned long decimal integer unsigned long
%x %X unsigned hexadecimal (x:lowercase, X:uppercase)
%o unsigned octal notation /
%% Displays '%' character itself. /
%* Specifies field width.
eg) printf("%*d", 0x0a, value); << The value is printed in field width 0x0a.
%e %E Scientific notation of float or double. If no specific precision specifier has been specified with F, it presents maximum 6 digits on the right of the floating point.
eg) 12.3 is presented as 1.230000e + 001
float, double(lowercase/uppercase)
  • Precision specifier(.n where n is a numeric constant) is applied only to the following conversion characters: e, E, f, g, G, s. If used with 's' it specifies the number of characters to be printed, otherwise the number of digits on the right of the floating-point.

  • 'l' modifier can be placed before the following conversion specifiers: o, u, x, X, i, d , b. It specifies long, not int.

  • 'l' modifier can be placed before the following conversion specifiers also: e, E, f, g. It specifies double.

printf conversion flag following '%' modifier

Flag Meaning
- Field output in left-alignment.
+ Preface numbers with '+' or '-' sign.
' ' Insert a space before a number.
# Applicable only to 'x', 'X' and 'o'. Preface a number that is not zero with '0x' or '0X' or '0' respectively.

Initializing multi-dimensional arrays

int array[2][3] = {1, 2, 3, 4, 5, 6};

is the same as the following:

int array[2][3] = {{1, 2, 3}, {4, 5, 6}};

Suspending operations for specified seconds

#include <time.h>
void sleep(int iseconds)
    clock_t duration;
    duration = (iseconds * CLOCKS_PER_SEC) + clock();

    while(duration > colck()) ;

struct definition/declaration/initialization and ...

    struct mystruct
        int a;
        int b;
    } one, two;

struct mystruct { int a; int b; } one = {3, 32};
struct shozi { struct mystruct numbers; char casio[0x20]; char mitsumi[0x30]; char fujitsu[0x30]; int value; float total; } one = { {0x04, 0x07}, "Casio", "Mitsumi", "Hard Disk", 235, 6344.323 };
union common { char c; int i; float f; long L; }; union common uione = {'A'}; << Union: initializing only the first member is enough as shown above.
typedef union _common { char c; int i; float f; long L; } common; common uione, uitwo; << Using typedef so as not to use union keyword for union variable declarations.

Sample Illustration

Multiple Indirection :
    int n = 0x0a;
    int *pi = &n;
    int **ppi = &pi;
    **ppi = 0xff;//Makes sense


    int multi[0x03][0x04] = {
        {0x01, 0x02, 0x03, 0x04},
        {0x05, 0x06, 0x07, 0x08},
        {0x09, 0x0a, 0x0b, 0x0c}
    // three lines and four columns.
    // multi and multi[index] is a pointer.

    int a = sizeof(multi);
    int b = sizeof(multi[0x00]);
    int c = sizeof(multi[0x00][0x00]);
    // c is the size of int, ie, 4 or 2.
    // b is the size of c * 0x04, ie 16 or 8.
    // a is the size of c * b, ie 64 or 16.

    int (*pi)[0x04];
    // A pointer that can point to an element of multi.

    int *pis[0x04];
    // An array of four int pointers
    // each of which can point to an int variable respectively.

    pi = multi;// Makes sense.
    pis = multi;// Wrong indirection;

#include <math.h> double ceil(double x); ceil(4.5) returns 5.0 ceil(-4.5) returns -4.0 double floor(double x); floor(4.5) returns 4.0 floor(-4.5) returns -5.0

Dont list

  • Do not put extended ASCII character value in signed char variable.

  • Avoid defining bit fields of eight or sixteen bits in size. (The same size as char or short type)

Mind list

  • Character sets supported by computer systems may vary but most have the same character values in the range from zero to one hundred twenty seven.

  • Bit field members must precede non-bit field members in struct definition.

        struct mystruct
            unsigned tagged:0x01;
            unsigned bogged:0x01;
            char name[0x20];
            char street[0x50];

Just O-shi-ra-se.

  • EOF is defined as -0x01 in stdio.h.

HOME | SynEdit in C++ | Kudaz | Tips | Links | User Comments

Bug-reports, suggestions, comments and constructive criticism are always welcome.
Send them, if any, to the e-mail address specified in any readme text you obtain.

Powered by C++ Builder
Copyright(C)2005-2006 Suzuki
Last update : September 11, 2006.