473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Fixed Struct Problem

I have the following struct that I'm trying to get to behave like a
union, where Unsigned* and Float* are structs.

[StructLayout(LayoutKind.Explicit)]
unsafe public struct Bits64 {
[FieldOffset(0)] public fixed Unsigned8 c[8];
[FieldOffset(0)] public fixed Unsigned16 s[4];
[FieldOffset(0)] public fixed Unsigned32 u[2];
[FieldOffset(0)] public fixed Float32 f[2];
[FieldOffset(0)] public Float64 d;
}

When I try to compile, I get the error:
Fixed size buffer type must be one of the following: bool, byte,
short, int, long, char, sbyte, ushort, uint, ulong, float or double

So I then tried the following and receive the error beneath it at runtime:

[StructLayout(LayoutKind.Explicit, Size=64)]
public class Bits64 {
[FieldOffset(0)] public Unsigned8[] c = new Unsigned8[8];
[FieldOffset(0)] public Unsigned16[] s = new Unsigned16[4];
[FieldOffset(0)] public Unsigned32[] u = new Unsigned32[2];
[FieldOffset(0)] public Float32[] f = new Float32[2];
[FieldOffset(0)] public Float64 d = new Float64();
}

Could not load type 'DIS.Bits64' from assembly 'TEST, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' because it contains an object
field at offset 0 that is incorrectly aligned or overlapped .

Help?
Oct 27 '06 #1
0 1261

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
2
by: Joshua Kolden | last post by:
STL allocators are templates so that when you write one you are obliged to make it work with any type. However, the Intel IPP library that we use has memory aligned allocators for each of 15...
3
by: Dr. Len | last post by:
Hi NG, is it possible for struct to have a fixed-length array of primitive types as member variable as in C++, such that the array doesn't need to be allocated explicitly? Eg.: --------...
2
by: AlanL | last post by:
I am calling a Fortran DLL that has a declaration like: character * 260 variablename. I do not have the Fortran code. A path to a file is passed to the DLL. C# does not have a fixed character...
2
by: Cyril | last post by:
Hello, I have a problem to marshal a structure that contains an array of an others struct. This array is an array size fixed (MyStruct myStructs and not MyStruct *myStructs). For example : ...
4
by: taskswap | last post by:
I'm converting an application that relies heavily on a binary network protocol. Within this protocol are a lot of byte arrays of character data, like: public unsafe struct MsgAddEntry {...
1
by: shofu_au | last post by:
Hi Group, I am trying to define a class that has a fixed size array of a structure containing a fixed size array of a structure. I am using System.Runtime.InteropServices and trying to define...
6
by: =?Utf-8?B?TFBldGVy?= | last post by:
Hi, I would copy the characters of a string variable to a fixed character buffer in a struct (and vice versa) in C#. public struct S { ... public fixed char cBuff; ...
0
by: colin | last post by:
Hi, I have many suitable structures wich I need to handle in a binary fashion, I can take the address of a struct inside unsafe and fixed block and this works when the struct is pased as a ref...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.