計算結構體基地址的巨集定義
前言:2014-08-06記錄在hi baidu上,現在移過來
winnt.h中定義的巨集
//
// Calculate the address of the base of the structure given its type, and an
// address of a field within the structure.
//
#define CONTAINING_RECORD(address, type, field) ((type *)( \
(PCHAR)(address) - \
(ULONG_PTR)(&((type *)0)->field)))
(ULONG_PTR)(&((type*)0)->field) 計算field相對於基地址的偏移
相關推薦
計算結構體基地址的巨集定義
前言:2014-08-06記錄在hi baidu上,現在移過來 winnt.h中定義的巨集 // // Calculate the address of the base of the
當結構體遇上巨集定義,以及函式指標的高階寫法(結構體中能用巨集定義一個函式?)
一、結構體中可以定義一般的巨集定義 如: struct aaa { #define STATUS_1 100 #define STATUS_2 200 #define STATUS_3 300 ........ }; 首先
結構體初始化及定義1
HA int tdi %d struct 初始 student har nbsp #include<stdio.h> struct student{ int num; char name[20]; float score; }; int m
類和結構體的遞迴定義
1.類的遞迴定義有兩個類這樣定義:Subject.h 標頭檔案如下:#ifndef SUBJECT_H#define SUBJECT_H#include <iostream>#include "Observer.h"class Subject{public:
一些可變長度物件(string物件、vector物件 ...)作為結構體或類的成員,會不會動態改變結構體或類所定義的變數的大小呢?
可能是我自身的原因,經常性的杞人憂天! 在接觸到C++的一些類時,想的有點多了。事實證明,我確實想多了。但是我覺得可能會有和我一樣會多想的小夥伴,我在這分享一個我想多了的栗
[演算法題] 計算結構體的大小
計算結構體的大小 C程式碼中定義的結構體是一塊連續記憶體,各成員按照定義的順序依次在其中存放。編譯器在完成語法分析後,需要計算它的大小,然後才能正確地為結構體分配空間。為了讓結構體的所有成員都能正確、快速地訪問,需要位元組對齊。 位元組對齊體現為:在成員之
C語言之struct大小、首地址與記憶體對齊—由結構體成員地址得到結構體首地址
被問到如下問題:給定一個結構體中某個變數地址,可否得到結構體變數的地址? 答案是可以,但是對不同的場合有不同的結果;這與微處理器平臺、編譯器的處理不可分割。 首先,對於處理器,大尾端、小尾端的因素必須考慮; 其次: 一、 ANSIC標準中並沒有規定,相鄰宣告的變數在記憶體中一定要相鄰。 為了程式的高效性,
C語言結構體及typedef關鍵字定義結構體別名和函式指標的應用
結構體(struct)的初始化 struct autonlist { char *symbol; struct nlist nl[2]
結構體陣列-sort自定義快排
1) #include <iostream> #include <string.h>//memser() #include <algorithm>//sort()
C語言根據結構體成員變數的地址,得到結構體的地址
/** * container_of - cast a member of a structure out to the containing structure * * @ptr: the pointer to the member. * @type: the type of the container s
動態計算結構體陣列長度
#include <stdio.h> #include <string.h> typedef struct S_MenuFun { int id; void
記憶體對齊方式的總結 如何計算結構體所佔記憶體的大小
具體的理論內容 神馬是記憶體對齊以及為何要記憶體對齊請看http://blog.csdn.net/kokodudu/article/details/11918219 上面這個連線 將的相當理論 我給簡化了一下 但是還是必須要看的 這裡對如何計算結構體所佔記憶體大小做出總結
關於計算結構體陣列中位元組數
2.結構體計算長度,如下: #include <stdio.h> #include <string.h> struct student { int num; char name[20]; char sex; float score;
結構體中的位定義
在工作中,經常遇到按位(bit)定義結構體 的情況。由於一個位元組有8個位,這時,程式設計師往往對bit的位置產生困惑。現在給出一個例子,來說明位的定義次序。 #pragma pack(push,1) typedef struct ST_TEST { unsigned
結構體&優先佇列 自定義排序
#include<bits/stdc++.h> using namespace std; typedef long long LL; struct node { LL d;//儲存距離 int u;//點的標號
C語言計算結構體佔用位元組大小總數
在學習C語言的時候很多人可能遇到了和我同樣的問題,就是無法正確計算出C語言結構體所佔位元組的總的大小。首先,在開始計算結構體佔用位元組大小之前,我們要先搞懂什麼是結構體的對齊和補齊。為什麼會有結構體的對齊與補齊。 CPU的資料傳輸方式: CPU的資料傳輸方式是一次傳輸2個(
結構體內的#define巨集定義
關於巨集的作用域 1. 巨集沒有可見域。 如果說有,那就是從本檔案(包括被包含的檔案)中,該巨集定義處開始,至檔案的尾部或取消巨集(#undef)為止。 2. 考慮一種特殊情況: 一個巨集定義,如果寫在結構體之內,即使與結構體之
我計算結構體和聯合體大小的方法
#include <stdio.h> struct A { int i; char ch[9]; }; void main() { struct A a
C-sizeof和strlen區別,以及sizeof如何計算結構體大小
struct alt inf 編譯 style img com 大小 運行 sizeof和strlen區別 sizeof是關鍵字,在編譯時就能計算出值,可以計算任何類型 strlen是函數,只有在運行時才能去計算,且只能計算字符型的. 對於數組時,strlen
C結構體和offset巨集
[Mac-10.7.1 Lion Intel-based x64 gcc4.2.1] Q: 結構體的本質是什麼? A: 結構體就像一種粘合劑,將事物之間的關係很好地組合在了一起。 Q: 結構體物件中各個變數的記憶體儲存位置和內建基本型別變數的儲存有什麼區別? A: 簡單地說,它們沒