Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #6640 > unrolled thread

const void * in structure

Started by"Skybuck Flying" <Windows7IsOK@DreamPC2006.com>
First post2011-06-12 02:07 +0200
Last post2011-06-12 12:42 -0400
Articles 4 — 4 participants

Back to article view | Back to comp.lang.c++


Contents

  const void * in structure "Skybuck Flying" <Windows7IsOK@DreamPC2006.com> - 2011-06-12 02:07 +0200
    Re: const void * in structure RaZiel <raziel_206_@hotmail.com> - 2011-06-12 05:51 +0200
    Re: const void * in structure "Heinrich Wolf" <invalid@invalid.invalid> - 2011-06-12 09:25 +0200
    Re: const void * in structure "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-06-12 12:42 -0400

#6640 — const void * in structure

From"Skybuck Flying" <Windows7IsOK@DreamPC2006.com>
Date2011-06-12 02:07 +0200
Subjectconst void * in structure
Message-ID<3f4f3$4df4035d$5419acc3$13678@cache4.tilbu1.nb.home.nl>
Hello,

I come across the following C/C++ code which is a bit unfamiliar to me:

const void *SomeField2; // *

typedef struct SomeStructureName1 {
    int SomeField1;
    const void *SomeField2; // *
    int SomeField3;
} SomeStructureName2;

It seems like a "constant void pointer type"

How to translate this structure to Delphi ?

My guess would be:

type
    SomeStructureName1 = record
        SomeField1 : integer;
        SomeField2 : pointer;
        SomeField3 : integer;
    end;
    SomeStructureName2 = SomeStructureName1;

Also is it just a "syntax" difference or is there a binary difference 
between

1. void *
vs
2. const void *

?

Bye,
  Skybuck. 

[toc] | [next] | [standalone]


#6642

FromRaZiel <raziel_206_@hotmail.com>
Date2011-06-12 05:51 +0200
Message-ID<it1d45$9f3$3@speranza.aioe.org>
In reply to#6640
On 12.06.2011 02:07, Skybuck Flying wrote:
> Hello,
>
> I come across the following C/C++ code which is a bit unfamiliar to me:
>
> const void *SomeField2; // *
>
> typedef struct SomeStructureName1 {
> int SomeField1;
> const void *SomeField2; // *
> int SomeField3;
> } SomeStructureName2;
>
> It seems like a "constant void pointer type"
>
> How to translate this structure to Delphi ?
>
> My guess would be:
>
> type
> SomeStructureName1 = record
> SomeField1 : integer;
> SomeField2 : pointer;
> SomeField3 : integer;
> end;
> SomeStructureName2 = SomeStructureName1;
>
> Also is it just a "syntax" difference or is there a binary difference
> between
>
> 1. void *
> vs
> 2. const void *
>
> ?
>
> Bye,
> Skybuck.

It's easier to read C++ declarations from right to left when pointers 
are involved. So the type is "pointer to constant void".

- RaZ

[toc] | [prev] | [next] | [standalone]


#6646

From"Heinrich Wolf" <invalid@invalid.invalid>
Date2011-06-12 09:25 +0200
Message-ID<it1pm4$7fd$1@news.m-online.net>
In reply to#6640
"Skybuck Flying" <Windows7IsOK@DreamPC2006.com> schrieb im Newsbeitrag 
news:3f4f3$4df4035d$5419acc3$13678@cache4.tilbu1.nb.home.nl...
> Hello,
>
> I come across the following C/C++ code which is a bit unfamiliar to me:
>
> const void *SomeField2; // *
>
> typedef struct SomeStructureName1 {
>    int SomeField1;
>    const void *SomeField2; // *
>    int SomeField3;
> } SomeStructureName2;
>
> It seems like a "constant void pointer type"
>
> How to translate this structure to Delphi ?
>
> My guess would be:
>
> type
>    SomeStructureName1 = record
>        SomeField1 : integer;
>        SomeField2 : pointer;

I agree.

>        SomeField3 : integer;
>    end;
>    SomeStructureName2 = SomeStructureName1;
>
> Also is it just a "syntax" difference or is there a binary difference 
> between
>
> 1. void *
> vs
> 2. const void *

no binary difference, just read-only.

> ?
>
> Bye,
>  Skybuck. 

[toc] | [prev] | [next] | [standalone]


#6658

From"Morris Keesan" <mkeesan@post.harvard.edu>
Date2011-06-12 12:42 -0400
Message-ID<op.vwy10gex5qv6o3@toshiba-laptop>
In reply to#6640
[most newsgroups trimmed from reply]

On Sat, 11 Jun 2011 20:07:57 -0400, Skybuck Flying wrote:
> Hello,
>
> I come across the following C/C++ code which is a bit unfamiliar to me:

Which is it?  C or C++?  They're two different languages.
My answer assumes that it's C code.

>
> const void *SomeField2; // *
>
> typedef struct SomeStructureName1 {
>     int SomeField1;
>     const void *SomeField2; // *
>     int SomeField3;
> } SomeStructureName2;
>
> It seems like a "constant void pointer type"

(void *) means a generic pointer to data, which can be converted to or
 from a pointer to any object type.
(const void *) means the same kind of pointer, but it points to
non-modifiable data.  So if if SomeField2 actually points to an (int),
then you can write

     const int *intp = SomeField2;

giving you a pointer to an int which you can't modify, but you can't
write

     int *intp = SomeField2;

because that discards the "const" modifier.  When the keyword "const"
appears in the position shown above, it refers to the pointed-to data.
If SomeField were itself a constant (unmodifiable) field, then the
declaration would be written "void * const SomeField2;".
-- 
Morris Keesan -- mkeesan@post.harvard.edu

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web