sizeof Questions

0

It's a fairly common idiom in the Win32 standard library to make the first member of structs be the size of the struct, like so: #include <cstddef> struct wrapped_float { std::size_t value...
Widener asked 18/7, 2019 at 22:33

4

Solved

The ISO C standard says that: sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) I am using GCC-8 on BIT Linux mint (19.1) and the size of long int is 8. I am using an app ...
Terle asked 15/5, 2019 at 19:37

5

Solved

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 ...
Rexanna asked 21/2, 2011 at 14:39

2

Solved

In (C and) C++, pointers to different types don't necessarily have the same size. I would have hoped void * is necessarily the largest, but it seems not even this is actually guaranteed. My questi...
Incestuous asked 18/4, 2019 at 12:16

3

Solved

Let's have this array: char arr[SIZE_MAX]; And I want to loop through it (and one past its last element): char *x; for (i = 0; i <= sizeof(arr); i++) x = &arr[i]; (Edited to ad...
Transmission asked 22/3, 2019 at 16:7

4

Solved

It happened to me that I needed to compare the result of sizeof(x) to a ssize_t. Of course GCC gave an error (lucky me (I used -Wall -Wextra -Werror)), and I decided to do a macro to have a signed...
Lek asked 22/3, 2019 at 15:4

1

Solved

I was reading an article about how to use the sizeof operator in C#. They say: "Used to obtain the size in bytes for an unmanaged type." I know the difference between managed and unmanaged code. ...
Spermato asked 20/2, 2019 at 15:49

1

Solved

I am using Ubuntu 16.04.5 and GCC version 5.4.0. I was playing with sizeof() operator, wrote the code below: #include <stdio.h> int main(int argc, char *argv[]){ long int mylint = 313313...
Isocracy asked 31/1, 2019 at 15:15

1

Is sizeof(Type) always divisible by alignof(Type) such that this statement will always be true? sizeof(Type) % alignof(Type) == 0
Scutch asked 27/1, 2019 at 2:13

6

Solved

Is it 12 bytes or 16 bytes when stored in a List<DataPoint>? public struct DataPoint { DateTime time_utc; float value; } Is there any sizeof function in C#?
Dickie asked 27/9, 2010 at 14:11

4

Solved

I need to find out a size of a generic structure (I can not do it like sizeof(T) or using Marshal.SizeOf(...) 0> gives me an error) So I wrote: public static class HelperMethods { static HelperM...
Goby asked 10/8, 2013 at 23:15

5

Solved

In the code below, why is the size of the packed structure different on Linux and Windows when compiled with gcc? #include <inttypes.h> #include <cstdio> // id3 header from an mp3 fil...
Shuttle asked 17/10, 2011 at 5:21

8

Solved

#include <stdio.h> int main(void){ char array[20]; printf( "\nSize of array is %d\n", sizeof(array) ); //outputs 20 printf("\nSize of &array[0] is %d\n", sizeof(&array[0]); //outp...
Deicide asked 26/6, 2013 at 12:37

4

Solved

#include <iostream> int main() { std::cout<<sizeof(0); return 0; } Here, sizeof(0) is 4 in C++ because 0 is an integer rvalue. But, If I write like this: std::cout<<sizeof(...
Bougie asked 6/10, 2018 at 6:30

2

Solved

code: #include<iostream> using namespace std; int main() { size_t i = sizeof new int; cout<<i; } In GCC compiler, working fine without any warning or error and printed output 8...
Hiltner asked 3/10, 2018 at 10:1

1

Solved

In C++11, it is easy to SFINAE on whether or not an expression is valid. As an example, imagine checking if something is streamable: template <typename T> auto print_if_possible(std::o...
Acidity asked 26/9, 2018 at 9:53

21

Solved

I have a data type, say X, and I want to know its size without declaring a variable or pointer of that type and of course without using sizeof operator. Is this possible? I thought of using standa...
Senegambia asked 2/8, 2009 at 16:22

1

suppose i have a function like this int writetofile(wstring name, any sdata){ ... return error; } This function have no idea about what data would be stored but would need to know the size of...
Intertidal asked 16/8, 2018 at 16:58

4

Solved

I'm quite new to C++ but I find this behaviour of auto weird: class A{}; int main() { A a; auto x = -(sizeof(a)); cout << x << endl; return 0; } Variable x is unsigned in this c...
Despondent asked 25/7, 2018 at 8:14

10

Solved

In C++, sizeof('a') == sizeof(char) == 1. This makes intuitive sense, since 'a' is a character literal, and sizeof(char) == 1 as defined by the standard. In C however, sizeof('a') == sizeof(int). ...
Neuroblast asked 11/1, 2009 at 22:43

4

Solved

I want to get sizeof of the type that is contained in a vector. Here is what I tried: #include <iostream> #include <vector> int main() { std::vector<uint> vecs; std::cout <...
Phototelegraph asked 22/1, 2014 at 18:21

5

#include <stdio.h> #include <string.h> int main(void) { char ch='a'; printf("sizeof(ch) = %d\n", sizeof(ch)); printf("sizeof('a') = %d\n", sizeof('a')); printf("sizeof('a'+'...
Isopropyl asked 4/7, 2018 at 12:41

6

Solved

I was searching for a way to find the size of an array in C without using sizeof and I found the following code: int main () { int arr[100]; printf ("%d\n", (&arr)[1] - arr); return 0; } ...
Joscelin asked 15/4, 2013 at 15:25

17

Solved

For example: sizeof(char*) returns 4. As does int*, long long*, everything that I've tried. Are there any exceptions to this?
Nardone asked 29/12, 2008 at 23:3

2

Solved

More specifically, a class, inheriting from an empty class, containing just a union whose members include an instance of the base data-less class, takes up more memory than just the union. Why does...
Orangeade asked 12/5, 2018 at 19:21

© 2022 - 2024 — McMap. All rights reserved.