C++ to C# conversion

G

GrzybSon

I've got following struct in C++

typedef struct TestStruct
{
const char * m_device;
unsigned m_value;
}

What size is m_device type;
What does const mean?

What size is m_value type?
 
B

Bart van Ingen Schenau

I've got following struct in C++

typedef struct TestStruct
{
    const char * m_device;
    unsigned m_value;

}

What size is m_device type;

It is the size of a pointer to char (sizeof(char*)). Probably it will
be 4 or 8 bytes.
What does const mean?

It means that the character(s) that m_device refers to can not be
changed by the program.
What size is m_value type?

It is sizeof(unsigned int) bytes. Probably 4.

Bart v Ingen Schenau
 
G

GrzybSon

Uzytkownik "Bart van Ingen Schenau" <[email protected]> napisal w
wiadomosci
I've got following struct in C++

typedef struct TestStruct
{
const char * m_device;
unsigned m_value;

}

What size is m_device type;
It is the size of a pointer to char (sizeof(char*)). Probably it will
be 4 or 8 bytes.

So on win32 systems it will be 4 bytes?
This code is run under VC++ 2005.
What does const mean?

It means that the character(s) that m_device refers to can not be
changed by the program.
What size is m_value type?
It is sizeof(unsigned int) bytes. Probably 4.

Thanx :)

Bart v Ingen Schenau
 
G

GrzybSon

Uzytkownik "Rolf Magnus said:
Yes, but why does that matter to you?

I've got unmanaged C++ dll that exports some functions, classes and
callbacks.
I want to use that DLL in C# under VS 2008.
Some of the exported functions returns complex types as instances of
unmanaged classes - pointers in memory.
To convert pointer to managed structers in C# i have to define managed
equivalent classes (or structs).

My next question:

typedef enum MyEnum
{
enum1,
enum2
}

what is the size of variable of type MyEnum in C++?
 
I

Ian Collins

GrzybSon said:
My next question:

typedef enum MyEnum
{
enum1,
enum2
}

what is the size of variable of type MyEnum in C++?

sizeof(int).

If your questions require answers that are windows specific, you might
be better of asking on a windows group.
 
Ö

Öö Tiib

what is the size of variable of type MyEnum in C++?


Write a small C++ program that answers all your such questions in
style:

std::cout << "sizeof( MyEnum ) is:"
<< sizeof( MyEnum )
<< std::endl;
 
S

Stefan Ram

GrzybSon said:
const char * m_device;
unsigned m_value;
What size is m_device type;

sizeof( char * )
What does const mean?

»The presence of a const specifier in a
decl-specifier-seq declares an object of const-qualified
object type; such object is called a const object.«

That was a quotation from ISO/IEC 14882:2003(E), but it
seems somewhat inappropriate, since after

char c;
char * p = &c;
char const * q = &c;

it give different assertions about whether the object c
is const or not.

So I'd say that const forbids write-operations to the
object of const-qualified type /via the identifier being
declared/.

ISO/IEC 14882:2003(E) say something similar at another
place:

»The referent of a const-qualified expression shall not
be modified (through that expression)«

But this is also rather vague, since it obviously is not
meant to be applied to:

*( int * const )p = 181
What size is m_value type?

sizeof( unsigned )
 
B

Balog Pal

Ian Collins said:
sizeof(int).

No, the implementation can pick almost any integral type that can represent
all the enumerators and their OR. So here 1 would be good. Compilers may
have switch to force enums to a bigger size like a whole int.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top