2,153 questions
Score of 0
1 answer
118 views
result of sizeof expected expression on array declaration [closed]
In drone.h,
I have a struct
typedef struct {
char name[MAX_DRONE_NAME_LENGTH];
enum drone_model model;
uint8_t status_bitarr;
} drone;
and a define
#define DRONE_STATUS_LENGTH (8*sizeof( ((...
Score of -1
1 answer
297 views
How to calculate len size from unsigned char* in C++20?
I had an idea to add texts for string but don't know how to calculate it for unsigned char*.
Is the size for const char* the same as const unsigned char*?
const std::string s = "....";
const ...
Score of -1
3 answers
137 views
sizeof operator appears to return wrong value for c type packed struct [duplicate]
Given the following C struct:
struct __attribute__((__packed__)) XIRControl
{
uint8_t command;
char code[19];
uint16_t error;
union codeData
{
struct rcvCommands
{
...
Score of 15
4 answers
1258 views
What is the size of std::array<T,0>?
Unlike C array, std::array is allowed to have zero length. But the current implementations differ in how std::array<T,0> is implemented, in particular the sizes of the object are different.
This ...
Score of 0
3 answers
297 views
What to use when malloc array length in c
When the array type is a "void *", then it can be allocated by:
void **void_array;
void_array = malloc(sizeof(void*) * 1);
But, if the array type is a struct Hello *, then what should be ...
Score of 3
4 answers
395 views
Is sizeof(pointer) the same as processor's native word size?
Say, is sizeof(void*) the same as the size processor can atomically access per instruction?
For example, 32-bit processor can read aligned 4 bytes atomically, 64-bit processor can read aligned 8 bytes ...
Score of 0
1 answer
123 views
Conditional compilation depending on the size of data type [duplicate]
This does not answer my need. I do not want to generate an error, I want to adapt the behavior of the software depending on the condition.
Example:
#if ( sizeof(unsigned long) == 4 )
# define a 5
#...
Score of 1
1 answer
346 views
Suspicious comparison of 'sizeof(expr)' to a constant
I did a static_assert to make sure that a valid type was used. I don't know if I just should have checked if the type is void, or whether any type can have size zero (I think it can with [[...
Score of 3
1 answer
159 views
Any way to create a SizeOf file in the Windows style as seen in the General tab of Properties, e.g., Size: 1.76 MB (1,856,000 bytes)?
I want to create a function like SizeOf() of C++ for powershell, but apparently Microsoft uses some strange algorithm/formula to determine the mebibytes.
Example:
If you create file with exactly 1.856....
Score of 2
4 answers
251 views
Why does \0 not affect the length of a string in C?
Consider this example where I add some extra \0 to a string.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv){
char str1[] = "dog";
char str2[] = &...
Score of 3
2 answers
222 views
Sizeof vs array size [closed]
I've got a question regarding the sizeof() operator. Browsing Open Source projects written in C obviously, some developers tend to use the sizeof() operator in one place and on other places the ...
Score of -6
1 answer
205 views
size of a struct in Go without initialising a variable of struct
There is one huge struct in our code, and its being passed around everywhere as a value.
I would like to be able to know the size(amount of memory in bytes, go will allocate for a variable of this ...
Score of 4
5 answers
283 views
Declare array based on size of another array
I have an array of color codes, the size of which is known at compile time. I want to declare another array of the same size. But the code below throws an error.
I can, of course, declare the size ...
Score of 3
1 answer
176 views
What is the effect of sizeof for hypothetically oversized objects?
Suppose we have the source:
#include <stdint.h>
#include <stdio.h>
struct foo
{
char b ;
char a [ SIZE_MAX ] ;
} ;
int main ( void )
{
const size_t z = sizeof ( struct foo ) ;
...
Score of 2
0 answers
126 views
Sizeof equality of direct members vs inherited members
Does the C++ standard have anything to say about the size equality of the following?
struct AB
{
int a;
int b;
}
Or
struct A
{
int a
};
struct B : public A
{
int b;
}
Is sizeof(...