473,386 Members | 1,785 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,386 software developers and data experts.

native vs value struct

1. Can a value struct inherit from a native struct?

2. Suppose I have a native structure:

struct Vector3
{
float x, y, z;
};

and you make a corresponding managed version

value struct VectorEx3
{
float x, y, z;
};

If you have a function that takes a pointer to a Vector3 as a
parameter, is it okay to cast a VectorEx3 object to it:

VectorEx3 v;
foo( (Vector3*)&v );

I tried it and it worked, but I want to make sure it is defined
behavior.
Dec 5 '07 #1
1 884

<dr*************@hotmail.comwrote in message
news:cb**********************************@e25g2000 prg.googlegroups.com...
1. Can a value struct inherit from a native struct?
No, a .NET value struct can never have a base class, only pure interfaces.
>
2. Suppose I have a native structure:

struct Vector3
{
float x, y, z;
};

and you make a corresponding managed version

value struct VectorEx3
{
float x, y, z;
};

If you have a function that takes a pointer to a Vector3 as a
parameter, is it okay to cast a VectorEx3 object to it:

VectorEx3 v;
foo( (Vector3*)&v );

I tried it and it worked, but I want to make sure it is defined
behavior.
It isn't guaranteed to work, and even adding the SequentialLayout attribute
only guarantees compatibility when passed through p/invoke. That said, as
long as you stick to the built-in numeric types, and structures thereof, I
don't think you'll run into any trouble.
>
Dec 7 '07 #2

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

Similar topics

2
by: Martin Zenkel | last post by:
Dear VS Team, using the Beta 2 of VS 2005 I've encontered the following problem. Let's assume threre are three Dll's, one unmanaged and two managed. In the unmanaged we put a simple unmanged...
2
by: RYoung | last post by:
Given this native struct: typedef struct vendor { char name; } VENDOR I want to make managed equivalent, so I did this: public value struct Vendor
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
1
by: nabil035 | last post by:
As the title of the question show I want to pass a pinny pointer (C++/CLI) pointer to a native function When Compiling there's no error but the pointer do not contain any value I explain...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.