Jump to content
Sign in to follow this  
aXXo

Define Variable

Recommended Posts

Kenapa variable tu di define kan sedemikian. Aku tak pernah jumpa pun dalam buku yang aku baca!

#define VXw(value) WriteReg((Opcode >> 8) & 0xf, value)

Cth penggunaan :

typedef unsigned char u8;

u8 memory[0xFFFF];

u8 V[16];

short value;

#define VXw(value) WriteReg((Opcode >> 8) & 0xf, value)

void CpuSetVX(){ //6XKK VX = KK

//CPU_LOG("VX = KK - Opcode = %x, PC = %x\n", Opcode, PC);

VXw(Opcode & 0xff); <-- Kat sini

}

void WriteReg(u8 location, u8 value){

V[location] = value;

}

Share this post


Link to post
Share on other sites

#define adalah preprocessor directive, direka untuk memudahkan/meringkaskan tugas yang berulang. Ia akan diproses terlebih dahulu oleh C preprocessor (textually). Biasanya dipanggil sebagai macros.

#define VXw(value) WriteReg((Opcode >> 8) & 0xf, value)
bermakna VXw adalah macro yang menerima satu argument bernama value. Basically awak bolehlah analogikan macro dengan fungsi. Jadi selepas macro definition ni, preprocessor C akan gantikan (dalam contoh di atas)
VXw(Opcode & 0xff);
dengan
WriteReg((Opcode >> 8) & 0xf, Opcode & 0xff)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...