Sunday, January 18, 2009

How to define "printf(...)" to "DEBUG(...)" in C/C++

When you make a program or programs, you need to check the program running condition.
In this reason, you want to use the debug message into the program.
In the debugging time you use the print put the logging messages and in the release time you don't want to use the logging messages.
When you use the macro "#define" how can you convert printf(char* format, ...) function to macro function?

As following,

// Multiple arguments
#define MSG_ERR(format, ...)    TRACE(ERROR, format, __VA_ARGS__)
#define MSG_WARN(format, ...)   TRACE(WARNING, format, __VA_ARGS__)
#define MSG_HIGH(format, ...)   TRACE(HIGH, format, __VA_ARGS__)
#define MSG_MID(format, ...)    TRACE(MIDDLE, format, __VA_ARGS__)
#define MSG_LOW(format, ...)    TRACE(LOW, format, __VA_ARGS__)
// Single argument
#define MSG_ERR(format)        TRACE(ERROR, format)
#define MSG_WARN(format)       TRACE(WARNING, format)
#define MSG_HIGH(format)       TRACE(HIGH, format)
#define MSG_MID(format)        TRACE(MIDDLE, format)
#define MSG_LOW(format)        TRACE(LOW, format)

And get more things, please refer to
Support for variadic macros was introduced in Visual C++ 2005.

Friday, January 16, 2009

About Bit Field in C/C++

In the C/C++, 
usually we use the "Bit Field" to optimize code or communicate with other process.
What is the Bit Filed?

I have attached "Example Code".

Example code

// Test Code, Bit Field
// ----------------------------------
{
 #define u8 unsigned char

 #define FILL_STRUCT1 u8:0; u8:8; u8:0;
 #define FILL_STRUCT2 u8:0; u8:8; u8:8; u8:0;
 #define FILL_STRUCT3 u8:0; u8:8; u8:8; u8:8; u8:0;

 typedef struct tag_SIMCommand {
 u8 Class;
 u8 Instruction;
 u8 P1;
 u8 P2;
 u8 P3;
 FILL_STRUCT3 // Bit Field
 u8 CData[8];
 } SIMCommandType;

 SIMCommandType SIMCommand;

 memset(&SIMCommand, 0xFF, sizeof(SIMCommandType));
 memset(&SIMCommand, 0x00, sizeof(SIMCommandType));

 // SELECT
 SIMCommand.Class = 0xA0;
 SIMCommand.Instruction = 0xA4;
 SIMCommand.P1 = 0x00;
 SIMCommand.P2 = 0x00;
 SIMCommand.P3 = 0x02;
 memset(SIMCommand.CData, 0xFF, sizeof(u8)*8);
}
// ----------------------------------

// Real Memory, Dump 1
// ----------------------------------
0012F3B0  A0 A4 00 00  
0012F3B4  02 00 00 00  
0012F3B8  FF FF FF FF  
0012F3BC  FF FF FF FF  
// ----------------------------------

// Test Code, Bit Field
// ----------------------------------
{
 #define u8 unsigned char

 #define FILL_STRUCT1 u8:0; u8:8; u8:0;
 #define FILL_STRUCT2 u8:0; u8:8; u8:8; u8:0;
 #define FILL_STRUCT3 u8:0; u8:8; u8:8; u8:8; u8:0;

 typedef struct tag_SIMCommand {
 u8 Class:4;
 u8 Instruction:2;
 u8 P1:1;
 FILL_STRUCT1
 u8 P2:4;
 FILL_STRUCT2
 u8 P3:1;
 FILL_STRUCT3 // Bit Field
 u8 CData[8];
 } SIMCommandType;

 SIMCommandType SIMCommand;

 memset(&SIMCommand, 0xFF, sizeof(SIMCommandType));
 memset(&SIMCommand, 0x00, sizeof(SIMCommandType));

 // SELECT
 SIMCommand.Class = 0x0F;
 SIMCommand.Instruction = 0x03;
 SIMCommand.P1 = 0x01;
 SIMCommand.P2 = 0x0F;
 SIMCommand.P3 = 0x01;
 memset(SIMCommand.CData, 0xFF, sizeof(u8)*8);
}
// ----------------------------------

// Real Memory, Dump 2
// ----------------------------------
0012F39C  7F 00 0F 00  
0012F3A0  00 01 00 00  
0012F3A4  00 FF FF FF  
0012F3A8  FF FF FF FF  
0012F3AC  FF CC CC CC  
// ----------------------------------

If you have any question? Please let me know :-)

Sunday, January 4, 2009

Soap opera, TV Drama?

Nowadays I am watching TV series
Grey's Anatomy: Season 1, 2, 3, 4, and 5
 now, I am watching season 2.

Previous time, I watched
LOST: Season 1, 2, 3, 4, and 5
 I already watched season 1, 2, and 3.
HEROES: Season 1, 2, and 3
 I already watched season 1, 2.
and NOW, I'm watching Gray's Anatomy.

Previous time, I have watched 24, Numb3rs, ... 

When I was school student, I have watched many Americana's TV series,
for example MacGyver, Air Wolf, The Wonder Years and so on.

In the future, can I watch these TV series without caption?



Thursday, January 1, 2009

Do you have a dream or a plan?

In the computer algorithm, there is "Divide and Conquer" i.e. when you solve the problem divide the problems and solve each of them. 

Today is the first working day of this year 2009.

Now, I am making this year's decision.

1. Increase family member.
2. Read English written books more than 10.
3. Join the on line lessons more than 10.
4. Upload blog more than 10 every month.

And end of this year, I will check them.

Let's start!

January 2nd, 2009.



Saturday, December 13, 2008

Do you know CRT?

CRT is NOT Cathode Ray Tube.
As I know, CRT is C RunTime Library's CRT.

And crt0;
in the wikipedia,
crt0 (or crt0.o, gcrt0.o, mcrt0.o) is a set of execution startup routines (usually part of the C standard library), platform-dependent, required in order to compile using the gcc and other GNU tools.
crt stands for 'c runtime'

Saturday, November 22, 2008

Read 2 books

인문의 숲에서 경영을 만나다 2, 정진홍
Think Innovation (씽크이노베이션) or イノベ-ションの本質, 노니카 이쿠지로, 가쓰미 아키라

Sunday, October 12, 2008

Do you know, auto, tempo ...

In India, you can find some transfers which are auto, tempo, and ... rickshaw
You can find pictures of them, here