Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++ to C# conversion

1 view
Skip to first unread message

GrzybSon

unread,
Feb 4, 2010, 9:24:16 AM2/4/10
to
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?

--
Regards,
Ma�ko

Bart van Ingen Schenau

unread,
Feb 4, 2010, 9:37:14 AM2/4/10
to
On Feb 4, 3:24 pm, "GrzybSon" <mrych...@kenbit.pl> wrote:
> 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.

>
> --
> Regards,
>  Maæko

Bart v Ingen Schenau

GrzybSon

unread,
Feb 4, 2010, 9:51:07 AM2/4/10
to
Uzytkownik "Bart van Ingen Schenau" <ba...@ingen.ddns.info> napisal w
wiadomosci
news:e85e1317-13ef-4f47...@g1g2000yqi.googlegroups.com...

On Feb 4, 3:24 pm, "GrzybSon" <mrych...@kenbit.pl> wrote:
> 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 :)

>
> --
> Regards,
> Ma�ko

Bart v Ingen Schenau

Rolf Magnus

unread,
Feb 4, 2010, 1:40:48 PM2/4/10
to
GrzybSon wrote:

>> 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.

Yes, but why does that matter to you?

GrzybSon

unread,
Feb 4, 2010, 4:50:11 PM2/4/10
to

Uzytkownik "Rolf Magnus" <rama...@t-online.de> napisal w wiadomosci
news:hkf4bg$10o$00$1...@news.t-online.com...

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++?

Ian Collins

unread,
Feb 4, 2010, 4:57:56 PM2/4/10
to
GrzybSon wrote:
>
> 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.

--
Ian Collins

Öö Tiib

unread,
Feb 4, 2010, 6:58:13 PM2/4/10
to
On Feb 4, 11:50 pm, "GrzybSon" <mrych...@kenbit.pl> wrote:
>
> 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;

Message has been deleted

Balog Pal

unread,
Feb 5, 2010, 3:23:22 AM2/5/10
to
"Ian Collins" <ian-...@hotmail.com> >> typedef enum MyEnum

>> {
>> enum1,
>> enum2
>> }
>>
>> what is the size of variable of type MyEnum in C++?
>
> 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.

Ruben Safir

unread,
Feb 16, 2010, 7:35:31 AM2/16/10
to


It might be that if your asking these very basic questions that your not
yet qualified to do this task. In fact, your question might not get you
the answer you need.

Ruben

0 new messages