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 ...
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 ...
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...
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...
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...
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. ...
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#?
4
Solved
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...
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...
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(...
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...
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...
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...
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...
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...
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'+'...
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;
}
...
17
Solved
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.