strict-aliasing

    0熱度

    2回答

    嚴格的別名讓我偏執。有時我用* int指針設置值,並且期望目標內存讀取相同的數據,而不管讀指針類型是什麼。嚴格的別名不能保證這一點,有時甚至會導致這種情況並非如此。 如果我在循環中讀取char [],並且在該char []數組中有一個* int chainging東西,我打破了其他標準C事物之間的別名規則。 我正在製作一個JIT編譯器,因爲我使用的是x86,所以我確信我不必關心int對齊。直到我們

    4熱度

    2回答

    另一個問題的答案是:Strict aliasing rule and 'char *' pointers表示使用char*檢查T對象的二進制內容是可以的。但是使用T*覆蓋char緩衝區並不好。 現在我有一個函數,它將二進制數據帶到char緩衝區。並在閱讀時做這樣的事情: // unsigned char *pData used to walk through the buffer. uint32

    1熱度

    3回答

    我知道int* ptr = (int*)buffer(其中buffer是char*)中斷 嚴格別名規則。 此語法int& ref = (int&)(*buffer)是否也違反規則? I had一些SEGFAULT由於違反了嚴格的別名規則,而且這種語法已經消除了這種情況。雖然可能還是不正確的,是嗎?

    2熱度

    2回答

    由於讀了很多警告不要使用工會這樣的: union rgba { struct { uint8_t r, g, b, a; } components; uint8_t index[4]; uint32_t value; }; ,因爲這是不確定的行爲,我決定讓事情變得簡單,像這樣: struct rgba { uint8

    1熱度

    2回答

    我需要使用readdir_r()來讀取多線程程序中目錄的內容。由於struct dirent的大小依賴於文件系統,man readdir_r建議 name_max = pathconf(dirpath, _PC_NAME_MAX); if (name_max == -1) /* Limit not defined, or error */ name_max = 255;

    3熱度

    2回答

    該問題與this post有關。 一些權威用戶聲稱以下代碼打破strict aliasing rules。 #include <boost/static_assert.hpp> template <typename T> struct MyType { private: T data; public: template <typename U>

    0熱度

    1回答

    #include "stdio.h" /* array to store data receeived from CAN Bus */ unsigned char a[8] = {0xCD, 0xEF, 0x12, 0x34, 0x50, 0x00, 0x00, 0x00}; typedef struct { unsigned int a:12; unsigned

    3熱度

    1回答

    相關的,但是從有些不同,Do any compilers transfer effective type through memcpy/memmove 在C89,memcpy和memmove需要表現得好像源和目標正在使用的字符類型訪問,複製的所有位源到目的地而不考慮被複制的數據的類型。 C99更改了語義,因此如果將具有有效類型的對象複製到沒有聲明類型的存儲器(通常是從malloc或其他此類函數接收

    7熱度

    1回答

    我已經看過以下相關的問題,並且它們都不能解決我的確切問題:one,two,three。 我寫其中的元件(鍵 - 值對)與一些記錄信息一起存儲的集合: struct Element { Key key; Value value; int flags; }; std::vector<Element> elements; (爲簡單起見,假定兩個Key和Value是

    1熱度

    1回答

    陣列我有這樣的功能: static void doSomething(int16_t array[256], int16_t mask, uint8_t skip){ uint16_t storage = array[skip]; uint64_t* array1=(uint64_t*)(array); uint64_t mask1 =0; uint16_t