structlayout Questions
2
Solved
This is more of a theoretical question.
I'm familiar with how padding and trailing padding works.
struct myStruct{
uint32_t x;
char* p;
char c;
};
// myStruct layout will compile to
// x: 4 Byt...
Dagnah asked 22/12, 2022 at 0:44
1
Solved
I do stuff where having contiguous data is required. Now with C# 10, we can do public readonly record struct.
I like having the automatic ToString feature that records have, among others, so having...
Shiner asked 17/10, 2021 at 18:49
1
I like the C# language very much. I'm just playing around, and would never use the code below in production code. Obviously the compiler is fooled by the layout of the struct. But how come, that th...
Gissing asked 7/4, 2017 at 14:20
3
Solved
I've just learned from Bug in VC++ 14.0 (2015) compiler? that one shouldn't make assumptions about how a struct's layout will end up in memory. However, I don't understand how it is common practice...
Cell asked 30/8, 2016 at 2:34
3
Solved
I declared the function Process32FirstW and the structure PROCESSENTRY32W like this:
[DllImport("KERNEL32.DLL", CallingConvention = CallingConvention.StdCall, EntryPoint = "Process32FirstW")]
priv...
Raffaello asked 10/11, 2015 at 14:27
6
Solved
Why does LayoutKind.Sequential work differently if a struct contains a DateTime field?
Consider the following code (a console app which must be compiled with "unsafe" enabled):
using System;
usin...
Willard asked 9/11, 2010 at 10:14
1
Solved
When running this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace StructLayoutTest
{
class Program
{
...
Stalemate asked 2/5, 2013 at 8:28
1
Solved
The struct System.DateTime and its cousin System.DateTimeOffset have their structure layout kinds set to "Auto". This can be seen with:
typeof(DateTime).IsAutoLayout /* true */
or:
typeof(DateT...
Eisenberg asked 19/2, 2014 at 13:13
2
Solved
Consider the following code:
using System;
using System.Runtime.InteropServices;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
const string test = "ABCDEF"; // Strings a...
Cudlip asked 23/12, 2010 at 14:26
7
Solved
I would like to do the following:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SomeStruct
{
public byte SomeByte;
public int SomeInt;
public short SomeShort;
public byte So...
Higa asked 14/7, 2009 at 19:54
2
Solved
I'm trying to understand why the second example below works with no issues, but the first example gives me the exception below. It seems to me that both examples should give an exception based on t...
Endurance asked 25/7, 2009 at 19:5
1
© 2022 - 2024 — McMap. All rights reserved.