offsetof

    3熱度

    5回答

    在C中,我看到offsetof的一些用法來計算結構中成員到其開始處的偏移量? 是否仍推薦在C++中使用?任何其他方式沒有這個宏來做到這一點?

    0熱度

    1回答

    如何知道結構中的所有成員如何位於內部? 我需要所有偏移量和大小的詳細列表 是否有IDE的任何插件,我使用Visual Studio 2013? 我不能使用偏移的或類似的東西,因爲我需要所有的領域 struct Test { int a; //0x0000 (4) float b; //0x0004 (4) bool c; //0x0008 (1) }; //Size

    2熱度

    4回答

    struct Data { int a; std::string b; float c; }; std::string* allocateDataAndGetString() { Data* dataPtr(someAllocator.allocate<Data>()); return &dataPtr.b; } Data* getBa

    -2熱度

    2回答

    我在使用X宏中的offsetof()時出現明顯錯誤。下面的代碼顯示了一個相當簡單的結構的例子,一個是明確定義的,另一個是使用X宏定義的。然後將兩個結構中每個結構域的偏移量打印到屏幕上。正如您在下面的註釋中看到的那樣,使用X宏定義的結構中的字段顯示不正確的偏移量。 我認爲這是一個打印問題。有人可以解釋一下這個謎團嗎? #include <stdio.h> #include <stdlib.h>

    0熱度

    1回答

    據我所知「offsetof」宏定義爲: #define offsetof(st, m) ((size_t)(&((st *)0)->m)) 基於此鏈接:http://en.wikipedia.org/wiki/Offsetof 所以,我寫我自己的代碼片段來計算偏移一個結構成員: typedef struct{ char a; int b; int c; }exa

    4熱度

    1回答

    該代碼適用於int,但是當我想使用浮點數時,它將失敗,除非我將該結構作爲字符指針進行投射。這裏是什麼樣子: struct test { float a; float b; }; void stuff(int offset, test* location); int main() { test *t; t = (test*)malloc(size

    1熱度

    1回答

    下面的代碼是在這裏:https://ideone.com/XnxAyw 編譯器的錯誤,我得到的是: prog.cpp: In member function ‘size_t list_base<T, NODE, true>::offset()’: prog.cpp:26:22: error: expected unqualified-id before ‘*’ token return off

    3熱度

    2回答

    一個解決方案打印在info結構的偏移checksum場的,是使用宏typeof和offsetof: #include <stdio.h> #include <stddef.h> #include <stdint.h> typedef struct { struct { int a; } something; struct { int

    1熱度

    1回答

    如果類is_standard_layout足夠保證給定的非靜態數據成員始終與對象的地址具有相同的偏移量(即在整個流程範圍內該類的不同實例中相同)?

    1熱度

    2回答

    在C中,結構的第一個元素與結構本身具有相同的地址。如果第一個元素是POD,那麼對於C++中的非POD結構也是如此? 例如,給出此代碼: struct bar { struct bar *p1, *p2; unsigned char h; } struct foo { struct bar node; int a; private: