顯示具有 c tech 標籤的文章。 顯示所有文章
顯示具有 c tech 標籤的文章。 顯示所有文章

2009年8月13日 星期四

匈牙利命名法 (For reference)

匈牙利命名法
變數名稱 = 屬性+類型+描述
屬性
" g_ 全域變數
" c_ 常數
" m_ 成員變數
類型
" n/ui int/unsigned int
" l/ ul long/unsigned long
" sh/us short/unsigned short
" f float
" d double
" ld long double
" ch char
" b boolean
" p pointer
" h handle
" str String
" w/dw WORD/DWORD
" b byte/unsigned char
" bl BOOL
描述
" Custom 自訂
" Src 來源
" Dst 目的
" Tmp 暫時

Other Reference:

Prefix

Data Type

Prefix

Data Type

c

char, TCHAR

bt

TBYTE, BYTE,

uc

UCHAR



s

short

us

USHORT

w

WORD

n

int, INT

u

UINT

l

LONG, long

dw

DWORD

ul

ULONG

fl

float

db

double

b

BOOL

f

bitwise flag fields

sz

ANSI string, terminated with a \0 character.

psz

PSTR

h

HANDLE

hmem

HGLOBAL, HLOCAL

hwnd

HWND

hfile

HFILE

hdc

HDC

hpen

HPEN

hfont

HFONT

hbmp

HBITMAP

hpal

HPALETTE

hmenu

HMENU

hicon

HICON

hinst

HINSTANCE

hcur

HCURSOR

hbr

HBRUSH

pt

POINT

rc

RECT

tm

TEXTMETRIC

lf

LOGFONT

bmp

BITMAPINFO

pal

PALETTEENTRY

cls

WNDCLASS

msg

MSG

rgb

RGBQUAD

clr

COLORREF

of

OFSTRUCT

ps

PAINTSTRUCT

cb

count of bytes

cx, cy

length in pixels

p

added for pointer to any type, e.g., ps, pdw, phicon, pof, ..., etc.

a

added for array of any type, e.g., as, adw, auc, ...

C

a big C in front of all C++ class names, the rest of the class name is a mix of big and small letters

m_

added in front of all C++ class member variables.

str

string



st

structure




2009年6月4日 星期四

suspend some seconds in the Linux/Windows

Linux
- sleep(n), , suspend n seconds
- usleep(n), suspend n * 10(-6) seconds

Windows
- Sleep(n) , suspend n * 10(-6) second

We can also use select to suspend n seconds m 10(-6) seconds

struct timeout tv;
tv.tv_sec = n;
tv.tv_usec = m;
select(0, NULL, NULL, NULL, &tv);

Then this function will suspend n seconds m 10(-6) seconds

2008年11月5日 星期三

Some hints in the C programming

1. Before using the character strings (either char array or malloc buffer), it is better to clean up all the buffer to zero (using memset(buf, 0, bufsize) or bzero function)

Question:
Sometimes we use the following declaration

char *mystr;

Then we can assign a string to the variable "mystr", like this. Is it valid to use this method?
mystr = "hello world";

2007年5月20日 星期日

Some C++ experience

1. type stringstream 的 member function
rdbuf Get/set the associated stringbuf object (public member function)

當呼叫過這一個rdbuf api 後, 原先stringstream 內的data 就會被刪除

str Get/set the associated string object (public member function)
如果只是想要顯示資料, 可以利用 str 這一個api 即可

至於其他的type, 如
ifstream
isstringstream
stream
等

ifstream public member functions
(constructor) Construct object and optionally open file (constructor member)
rdbuf Get the associated filebuf object (public member function)
is_open Check if a file is open (public member function)
open Open file (public member function)
close Close file (public member function)


istringstream public member functions
(constructor) Construct an object and optionally initialize its content (constructor member)
rdbuf Get/set the associated stringbuf object (public member function)
str Get/set the string content (public member function)

string

2007年5月11日 星期五

C 的特殊字元

- '\n' closes a line
- '\f' closes a page
- '\t' prints a tab wide spaces (whereas the definition of the tab
depends on the driver attached to the stream.)
- '\b' lets the logical cursor go a char backwards
whereas this cursor may be a the cursor on screen, the printhead,
a pinter inside the print buffer on the device or the driver....
- '\a' may ring a bell, a siren, or another device that
does require the attention of the operator or even does nothing when
no device that can be activated on that signal gets activated.
On a PC it will give traditionally a signal to the speaker or
play a wave file through the soudcard - or even do nothing or
something else.

2007年4月16日 星期一

C Operator Precedence and Associativity

http://www.difranco.net/cop2220/op-prec.htm

Operator
Description Associativity

()
[]
.
-> Parentheses (grouping)
Brackets (array subscript)
Member selection via object name
Member selection via pointer left-to-right

++ --
+ -
! ~
(type)
*
&
sizeof Unary preincrement/predecrement
Unary plus/minus
Unary logical negation/bitwise complement
Unary cast (change type)
Dereference
Address
Determine size in bytes right-to-left
* / % Multiplication/division/modulus left-to-right
+ - Addition/subtraction left-to-right
<< >> Bitwise shift left, Bitwise shift right left-to-right
< <=
> >= Relational less than/less than or equal to
Relational greater than/greater than or equal to left-to-right
== != Relational is equal to/is not equal to left-to-right
& Bitwise AND left-to-right
^ Bitwise exclusive OR left-to-right
| Bitwise inclusive OR left-to-right
&& Logical AND left-to-right
|| Logical OR left-to-right
?: Ternary conditional right-to-left
=
+= -=
*= /=
%= &=
^= |=
<<= >>= Assignment
Addition/subtraction assignment
Multiplication/division assignment
Modulus/bitwise AND assignment
Bitwise exclusive/inclusive OR assignment
Bitwise shift left/right assignment right-to-left
,
Comma (separate expressions) left-to-right