sizeof

Why is the sizeof(int) == sizeof(long)?

こ雲淡風輕ζ 提交于 2019-12-30 08:07:12
问题 In the program listed below, the sizeof(int) and sizeof(long) are equal on my machine (both equal 4 bytes (or 32 bits)). A long, as far as I know, is 8 bytes. Is this correct? I have a 64-bit machine #include <stdio.h> #include <limits.h> int main(void){ printf("sizeof(short) = %d\n", (int)sizeof(short)); printf("sizeof(int) = %d\n", (int)sizeof(int)); printf("sizeof(long) = %d\n", (int)sizeof(long)); printf("sizeof(float) = %d\n", (int)sizeof(float)); printf("sizeof(double) = %d\n", (int

《深度探索c++对象模型》chapter3 Data语意学

我与影子孤独终老i 提交于 2019-12-30 03:31:38
一个空的class:如 class X{} ; sizeof(X)==1; sizeof为什么为1,他有一个隐晦的1 byte,那是被编译器安插进去的一个char,这使得class2的两个objects得以在内存中配置独一无二的地址: X a,b; if(&a==&b) cerr<<"yipes!"<<endl; class X{}; class Y:public virtual X{}; class Z:public virtual X{}; class A:public Y,public Z{}; cout<<"sizeof(X):"<<sizeof(X)<<endl; cout<<"sizeof(Y):"<<sizeof(Y)<<endl; cout<<"sizeof(Z):"<<sizeof(Z)<<endl; cout<<"sizeof(A):"<<sizeof(A)<<endl; 我的vs结果是1 ,4,4,8. 但是让人搞不懂的是Y、Z的大小。主要大小受三个因素的影响: 语言本身所造成的额外负担,当语言支持虚基类virtual base class的时候,就导致一个额外的负担,这个一般反映在某种形式的指针身上,它或者指向virtual base class subobject,或者指向一个相关表格。 编译器对于特殊情况所提供的优化处理,因为class X有1

Pointer implementation details in C

别说谁变了你拦得住时间么 提交于 2019-12-30 01:51:13
问题 I would like to know architectures which violate the assumptions I've listed below. Also, I would like to know if any of the assumptions are false for all architectures (that is, if any of them are just completely wrong). sizeof(int *) == sizeof(char *) == sizeof(void *) == sizeof(func_ptr *) The in-memory representation of all pointers for a given architecture is the same regardless of the data type pointed to. The in-memory representation of a pointer is the same as an integer of the same

笔记整理——使用openssl编程

萝らか妹 提交于 2019-12-29 22:42:20
error: openssl 的所有解决方案 (2013/6/22 17:39:00) error: openssl/crypto.h: No such file or directory 解决方案 (2013/6/22 17:39:00) error: openssl/crypto.h: No such file or directory error: openssl/md5.h: No such file or directory 解决方案 libssl-dev 没有安装,只要 sudo apt-get install libssl-dev 就可以了 libssl-dev 没有安装,只要 sudo apt-get install libssl-dev 就可以了 undefined reference to `MD5'_fengzi_lu的空间_百度空间 - Google Chrome (2013/8/8 15:23:26) undefined reference to `MD5' 这是因为包含md5函数的库为/usr/lib/libcrypto.a(.so),所以编译时使用 -lcrypto 就OK了。 基于X.509证书和SSL协议的身份认证过程实现 - 菜鸟浮出水 - 51CTO技术博客 - Google Chrome (2013/6/7 17:14:52) 客户端程序代码

sizeof union larger than expected. how does type alignment take place here?

浪子不回头ぞ 提交于 2019-12-29 08:48:05
问题 #include <stdio.h> union u1 { struct { int *i; } s1; struct { int i, j; } s2; }; union u2 { struct { int *i, j; } s1; struct { int i, j; } s2; }; int main(void) { printf(" size of int: %zu\n", sizeof(int)); printf("size of int pointer: %zu\n", sizeof(int *)); printf(" size of union u1: %zu\n", sizeof(union u1)); printf(" size of union u2: %zu\n", sizeof(union u2)); return 0; } Results in: $ gcc -O -Wall -Wextra -pedantic -std=c99 -o test test.c $ ./test size of int: 4 size of int pointer: 8

invalid application of 'sizeof' to incomplete type 'struct array[]'

耗尽温柔 提交于 2019-12-29 06:25:29
问题 I am trying to organize my project by splitting commands up into separate files for easier maintenance. The issue I am having is trying to iterate over the array of commands defined at compile time. I have created a dumbed down example that reproduces the error I am getting. . ├── CMakeLists.txt ├── commands │ ├── CMakeLists.txt │ ├── command.c │ ├── command.h │ ├── help_command.c │ └── help_command.h └── main.c ./CMakeLists.txt PROJECT(COMMAND_EXAMPLE) SET(SRCS main.c) ADD_SUBDIRECTORY

sizeof() std::vector (C++)

房东的猫 提交于 2019-12-29 05:21:06
问题 There is a topic already on this topic but I have doubts still. To calculate the size of a vector, which one is correct: sizeof(VEC) + sizeof(int) * VEC.capacity() or VEC.capacity() * (sizeof(VEC) + sizeof(int)) 回答1: What do you mean by size of the vector? The size of the vector object is just sizeof(vec); If you are interested in how much memory the vector has allocated on the heap, you can use vec.capacity()*sizeof(T) So, if you add these, you'll get how much memory you've "lost" because of

Sizeof array through function in C [duplicate]

不想你离开。 提交于 2019-12-29 02:09:54
问题 This question already has answers here : How to find the 'sizeof' (a pointer pointing to an array)? (13 answers) Closed 5 years ago . I'm not sure why I cannot use sizeof(array) when passing the array through my function only outputs a value of 1, instead of 1000000. Before passing the array to the function, I printed out the sizeof(array) to get 4000000 and when I try to printout the sizeof(array) in the function, I only get 4. I can iterate through the array in both the function and the

Sizeof array through function in C [duplicate]

北城以北 提交于 2019-12-29 02:09:10
问题 This question already has answers here : How to find the 'sizeof' (a pointer pointing to an array)? (13 answers) Closed 5 years ago . I'm not sure why I cannot use sizeof(array) when passing the array through my function only outputs a value of 1, instead of 1000000. Before passing the array to the function, I printed out the sizeof(array) to get 4000000 and when I try to printout the sizeof(array) in the function, I only get 4. I can iterate through the array in both the function and the

c++实现Windows内存监视

喜欢而已 提交于 2019-12-28 22:51:21
问题描述 设计一个内存监视器,能实时地显示当前系统中内存的使用情况,包括系统地址空间的布局,物理内存的使用情况;能实时显示某个进程的虚拟地址空间布局和工作集信息等。 思路 获取系统信息 SYSTEM_INFO typedef struct _SYSTEM_INFO { union { DWORD dwOemId; struct { WORD wProcessorArchitecture; WORD wReserved; } DUMMYSTRUCTNAME; } DUMMYUNIONNAME; DWORD dwPageSize; LPVOID lpMinimumApplicationAddress; LPVOID lpMaximumApplicationAddress; DWORD_PTR dwActiveProcessorMask; DWORD dwNumberOfProcessors; DWORD dwProcessorType; DWORD dwAllocationGranularity; WORD wProcessorLevel; WORD wProcessorRevision; } SYSTEM_INFO, *LPSYSTEM_INFO; GetNativeSystemInfo 注意INTELx86_64体系最好用这个函数。其他的等价于 GetSystemInfo void