sizeof Questions

5

I'm hoping this isn't a duplicate question, but I've searched in some detail and haven't found my exact case before. I have a simple struct that I also want to be able to access as a simple byte a...
Inhabitancy asked 7/5, 2014 at 18:46

3

Solved

How can I check the size of an unsigned in the preprocessor under g++? sizeof is out of the question since it is not defined when during preprocessing.
Induce asked 6/4, 2010 at 13:1

2

Solved

Context The standard says (C17, 6.5.3.4 ¶2): The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined f...

7

Solved

I have two structures, with values that should compute a pondered average, like this simplified version: typedef struct { int v_move, v_read, v_suck, v_flush, v_nop, v_call; } values; typedef st...
Unemployment asked 2/4, 2011 at 17:0

16

For now, I am using a static assert (home brewed based on other web resources) to compare the sizeof() result to various constants. While this works, it is far from elegant or fast. I can also crea...
Seneschal asked 7/1, 2014 at 18:57

17

How do I get the size occupied in memory by an object in Python?
Lovage asked 16/1, 2009 at 5:7

5

Solved

On a microcontroller, in order to avoid loading settings from a previous firmware build, I also store the compilation time, which is checked at loading. The microcontroller project is build with 'm...
Acanthopterygian asked 15/1 at 12:45

3

Solved

I have the following class, struct employee { std::string name; short salary; std::size_t age; }; Just as an example, in Linux amd64, the size of the struct is 48 bytes, and the size of std::st...
Matheny asked 7/11, 2023 at 5:2

7

Solved

Is this the simplest/shortest way to get size in memory of the content of what std::array::data() returns? arr.size() * sizeof(arr.value_type) Edit: My question wasn't precise. By "size in memor...
Angele asked 27/9, 2017 at 13:4

2

Solved

TL;DR I have a struct with more than just member variables (e.g. they contain functions), and I want to convert only the member variables into a byte array(/vector), such that I can upload data to ...
Placement asked 6/9, 2023 at 12:19

6

Solved

I just found this code on Wikipedia. Link: http://en.wikipedia.org/wiki/Sizeof#Use The code: /* the following code illustrates the use of sizeof * with variables and expressions (no parentheses...
Leia asked 28/5, 2010 at 16:18

9

Solved

This is a C++ interview test question not homework. #include <iostream> using namespace std; enum months_t { january, february, march, april, may, june, july, august, september, october, ...
Hypnology asked 13/11, 2011 at 23:13

6

Solved

I want to be able to vary the size of my array so I create one this way: int* array; array = malloc(sizeof(int)*10);//10 integer elements I can use this like an array as you normally would, howe...
Vincenty asked 26/8, 2012 at 16:42

12

Solved

So I have an array of strings. Here's an example: std::string array[] = {"Example", "Example2", "Example3"}; Is there any way I can find the number of elements in an ...
Madore asked 13/1, 2013 at 22:29

4

Solved

In order to understand the memory consumption of std::vector<int> I wrote: std::cout << sizeof(std::vector<int>) << std::endl; This yields 32. I tried to understand where...
Printable asked 27/11, 2017 at 9:31

4

Solved

My project demands a complete understanding of how the sizeof operator works. The C standard specification in this regard is vague and it will be dangerous to rely on my interpretations of it. I am...
Alduino asked 2/2, 2023 at 12:42

6

Solved

I'm trying to use 64 bit integers in C, but am getting mixed signals as to whether it should be possible. When I execute the printf: printf("Size of long int:%d\nSize of long long int:%d\n\n",(in...
Diapositive asked 7/3, 2012 at 17:38

6

Solved

I'm having a look at Go, which looks quite promising. I am trying to figure out how to get the size of a go struct, for example something like type Coord3d struct { X, Y, Z int64 } Of course I ...
Mur asked 21/1, 2010 at 23:18

6

Solved

For what design reason is there no sizeof operator in Java? Knowing that it is very useful in C++ and C#, how can you get the size of a certain type if needed?
Violoncellist asked 1/12, 2011 at 18:21

6

Solved

As the title implies, my question is how to get the size of a string in C. Is it good to use sizeof if I've declared it (the string) in a function without malloc in it? Or, if I've declared it as a...
Eskill asked 21/2, 2013 at 11:0

4

Solved

Well, after reading this Size of structure with a char, a double, an int and a t I still don't get the size of my struct which is : struct s { char c1[3]; long long k; char c2; char *pt; char...
Brokendown asked 18/12, 2014 at 20:37

5

Solved

So, you know how the primitive of type char has the size of 1 byte? How would I make a primitive with a custom size? So like instead of an in int with the size of 4 bytes I make one with size of le...
Salesmanship asked 21/4, 2010 at 1:45

13

Solved

Why does the sizeof operator return a size larger for a structure than the total sizes of the structure's members?
Cryogenics asked 23/9, 2008 at 4:24

1

Solved

I don't understand how sizeof behaves differently when both the lists are created like literals. I expect the output of the second sizeof to be equal or less than that of the first sizeof, not grea...
Uvarovite asked 5/4, 2022 at 20:14

17

Solved

First off, here is some code: int main() { int days[] = {1,2,3,4,5}; int *ptr = days; printf("%u\n", sizeof(days)); printf("%u\n", sizeof(ptr)); return 0; } Is there a way to find out the...
Clactonian asked 29/1, 2009 at 16:33

© 2022 - 2024 — McMap. All rights reserved.