sizeof

Get the sizeof Object's Members

…衆ロ難τιáo~ 提交于 2019-12-11 12:34:47
问题 There is an object who's members I need to find the size of. I am specifically asking for the object's size without it's v-table considered. Also, I cannot modify it, so I cannot take advantage of this answer. Is there a provision for this in C++, beyond summing a hard-coded sizeof for each member? I am aware that v-tables are not mandated by C++. I am also aware that anything I do with this information will be widely considered "bad form". This question is simply asking if it's possible, not

C中的函数指针如何工作?

倖福魔咒の 提交于 2019-12-11 11:28:47
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我最近对C中的函数指针有一些经验。 因此,继续回答您自己的问题的传统,我决定为那些需要快速学习该主题的人做一些基本的总结。 #1楼 函数指针的另一个好用法: 轻松切换版本 当您在不同的时间或不同的开发阶段需要不同的功能时,它们非常方便使用。 例如,我正在具有控制台的主机上开发应用程序,但是该软件的最终版本将放在Avnet ZedBoard上(该端口具有用于显示和控制台的端口,但不需要/不需要它们用于)。最终版本)。 因此,在开发过程中,我将使用 printf 来查看状态和错误消息,但是当我完成后,我什么都不想打印了。 这是我所做的: 版本 // First, undefine all macros associated with version.h #undef DEBUG_VERSION #undef RELEASE_VERSION #undef INVALID_VERSION // Define which version we want to use #define DEBUG_VERSION // The current version // #define RELEASE_VERSION // To be uncommented when finished debugging #ifndef _

c语言类型浅谈

余生颓废 提交于 2019-12-11 08:30:00
C语言中的基本类型 //有符号类型 signed char; //1byte short; //2byte int; //4byte long int ; //4byte long long; //8byte //无符号类型 unsigned char; //1byte unsigned short; //2byte unsigned int; //4byte unsigned long int; //4byte unsigned long long; // 8byte //浮点型 float; //4byte double; //8byte long doube; //c11 12byte//c99 8byte //布尔型 //c语言中可能会用到#include<stdbool.h>头文件 bool; //1byte false true; //空类型 void; //不能定义变量,可以定义指针 # include <stdio.h> int main ( ) { printf ( "char型变量的大小为%d" , sizeof ( char ) ) ; printf ( "short型变量的大小为%d" , sizeof ( short ) ) ; printf ( "int型变量的大小为%d" , sizeof ( int ) ) ; printf ( "long

剑指Offer学习

[亡魂溺海] 提交于 2019-12-11 07:49:33
目录: 1、 【剑指Offer学习】【面试题01:实现赋值运算符函数】 2、 【剑指Offer学习】【面试题02:实现Singleton 模式——七种实现方式】 3、 【剑指Offer学习】【面试题03:二维数组中的查找】 4、 【剑指Offer学习】【面试题04:替换空格】 5、 【剑指Offer学习】【面试题05:从尾到头打印链表】 6、 【剑指Offer学习】【面试题06:重建二叉树】 7、 【剑指Offer学习】【面试题07:用两个栈实现队列】 8、 【剑指Offer学习】【面试题08:旋转数组的最小数字】 9、 【剑指Offer学习】【面试题09:斐波那契数列】 10、 【剑指Offer学习】【面试题10:二进制中1 的个数】 1、 【剑指Offer学习】【面试题01:实现赋值运算符函数】 //================================================================== // 《剑指Offer——名企面试官精讲典型编程题》代码 // 作者:何海涛 //================================================================== // 面试题1:赋值运算符函数 // 题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数。 #include

使用memset()要注意

老子叫甜甜 提交于 2019-12-11 07:00:22
原型如下: ptr是要写入的内存块的指针,value是要写入的值,num是从ptr指向的首地址开始一共要写入的字节数。 要注意num传入的参数 错误示范: 实际上sizeof(InDegree)是4,等于sizeof(int)。也就是说这里的num参数只是一个指针的大小,没有完成初始化工作,除了第一个数组元素外,剩下的都是随机值。 应该改成: 来源: https://www.cnblogs.com/mrlonely2018/p/12020171.html

Easiest way to determine sizeof( double ) and sizeof( int ) from Ruby?

浪子不回头ぞ 提交于 2019-12-11 06:57:43
问题 For unpacking complex binary strings with mixed doubles and integers using Ruby's String.unpack I need to determine offsets within the binary string. Commonly, doubles are 8 bytes and integers are 4 bytes, but in order to make my code machine-independent, I would like to query these sizes from within my Ruby code. What is the easiest way to determine the size of integers and doubles from within Ruby, i.e., request the response of a request to C's sizeof( type ) method? 回答1: I have found a

Sizeof() difference between C++ on PC and Arduino [duplicate]

五迷三道 提交于 2019-12-11 06:36:55
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why isn't sizeof for a struct equal to the sum of sizeof of each member? In the following code, the value of structSize is different depending on whether it's executed on an Arduino vs my PC (Ubuntu 11.04 x64). struct testStruct{ uint8_t val1; uint16_t val2; }; ... uint_8_t structSize = sizeof(testStruct); On my PC, the value of structSize is 4, and on my Arduino the value of structSize is 3 (as expected). Where

char pointer as function parameter

牧云@^-^@ 提交于 2019-12-11 06:35:46
问题 I have a function A that has a char * parameter. In A() , I use sizeof to calculate the size of buf , but I got 8 in i686 machine and 4 in armel machine. why is not it 128? The snippet is as below: void A(char *p) { printf("sizeof p is %d\n", sizeof(p)); } int main(void) { char buf[128]; printf("sizeof buf is %d\n", sizeof(buf)); A(buf); return 0; } the result is like this(in i686): sizeof buf is 128 sizeof p is 8 Please tell me the reason. 回答1: Because you print the size of the pointer , and

Create “custom typeid” for many types AND cache their sizeof()

送分小仙女□ 提交于 2019-12-11 06:23:20
问题 There are many type of elements E0,E1,... , all of them derived from Element . class Element{ public: int id=0; } //"Element" can be edited class E0: public Element{ ... } class E1: public Element{ ... } ... class E999: public Element{ ... } How to cache sizeof() for E0,E1,... ? It has to return the correct value [#2] later by "custom typeid" [#1]. class CCollection{ template<class EX> EX* create(){ //(Edit) //all EX* is created by this function } /** user only pass EX*, never pass Element* *

Number of bits in basic data type

杀马特。学长 韩版系。学妹 提交于 2019-12-11 06:15:35
问题 Here's a couple of thoughts.I'm learning so there might be mistake(s) and even missing some basics. sizeof operator returns number of bytes. number of bits in byte is not constant value(correct me but it's number of bits char has). I want to know how many bits variable occupies, and sizeof won't tell me that without making assumptions about number of bits in char. So I came up with this piece of (probably unnecessary) code: #include <stdio.h> #include <math.h> #include <limits.h> int main