Planet of NCCUCS
dosbox windows resolution Buy Microsoft Windows Server 2008 Web Edition SP2 configure internet connection on windows xp consumer ratings on vinyl windows Buy Microsoft Windows 7 Professional buy dhcp windows 2000 server apple usb keyboard windows drivers Buy Microsoft Office Visio Professional 2007 buy windows xp registration number buy windows applications Buy Microsoft Windows XP Professional SP3 disable autoplay cd windows 2000 asms windows xp home Buy McAfee Total Protection 2009 autocad lt autodesk contemporary windows Buy Cyberlink PowerDVD 8 Ultra check windows genuine effects for windows movie maker Buy Corel VideoStudio Pro X2 audio codec windows cannot end programs in windows xp Buy CorelDraw Graphics Suite X4 borland delphi 5 and windows vista cannot open windows updates Buy Autodesk AutoCAD 2009 checkpoint ngx r65 windows 2003 download terminal services client windows 2000 Buy Autodesk AutoCAD 2010 download windows xp file debug windows application Buy Autodesk 3Ds Max Design 2009 convert dbx outlook express windows mail automatically reboot windows xp Buy Ahead Nero 9 ashampoo defrag windows xp serious error cannot install printer driver windows 2000 Buy Microsoft Office 2003 Professional apple toolbar for windows delay write failed windows xp Buy Microsoft Office 2007 Enterprise cleanup windows startup

差點被考到的程式碼

作者:lui on 八月 27, 2008 Posted in RSS | | 觀看文章來源

昨天面試 其中一個主管很在意coding能力

我也跟他說我coding很好

他就要考考我

考了兩題後 他發現太無趣了 就從一堆題目中找了一題出來

說這題過去沒幾個人講的出來

#define fun(A, b) (int)(&(((A *)0)->b))

typedef struct {
  char str[40];
  int type;
  int maxLen;
} intf;

問題是fun(intf, maxLen)的值為多少



看到第一眼時 先假裝鎮定 但不解 A * 的作用

因為腦殘沒看到typedef 想說A替換後只是變數不是型別

所以就靠推理的方式理解成強制轉型為pointer 並以此位置為0

所以b的位置就是 sizeof(char) * 40 + sizeof(int)

答案是對的 還告訴我它叫offset 差點被他唬到



回家查了一下

原來這個code是在stddef.h裡

目的是做出泛型計算變數在struct的offset

:

讀過本文的讀者, 也對以下文章有興趣

No comments for this entry yet...

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

最新文章

照片

R0012028R0012036R0013553R0013551R0013550R0013549R0013560R0013558R0013569R0013561R0013570R0013571R0013580R0013581R0013556R0013567R0013563R0013572R0011783R0012312