Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C Programming Language

const c structure question


Hi all,

I have this struct typedef:

typedef struct
{
        int * test;

}testst;

and have this declaration:

const testst abc;

What is constant? The pointer (like in: int * const test) or the integer
(like in const int * test) or both?

Thanx,

Milux

"nospam" <""miluxkloosterman\"@(nospam)home.nl"> wrote in message

news:f446g0$qm5$1@netlx020.civ.utwente.nl...

> Hi all,

> I have this struct typedef:

> typedef struct
> {
> int * test;
> }testst;

> and have this declaration:

> const testst abc;

> What is constant?

The object named 'abc'.

> The pointer (like in: int * const test) or the integer (like in const int
> * test) or both?

The entire object is const.  Which means that each
individual member of the struct is const.  Your struct
contains only one member, a pointer (type 'int*'), there
is no type 'int' member. So it's not a question of 'one
of or both', since that presumes two members.  The pointer
'test' is const.  What it points to (if anything) is not
const.  A pointer to a const int is declared:

const int *p;

or

int const *p;

What specifically are you trying to do?  Write
code for a particular task, or understand something
written by someone else?

-Mike

In article <f446g0$qm@netlx020.civ.utwente.nl>,

nospam  <""miluxkloosterman\"@(nospam)home.nl"> wrote:
>Hi all,

>I have this struct typedef:

>typedef struct
>{
>    int * test;
>}testst;

For the purposes of exploring constness, the struct is unnecessary
obfuscation. The question would apply just as well to

  typedef int *testp;

>and have this declaration:

>const testst abc;

  const testp abcde;

>What is constant? The pointer (like in: int * const test) or the integer
>(like in const int * test) or both?

abcde is a const pointer to non-const int.
abc.test is also a const pointer to non-const int.

--
Alan Curry
pac@world.std.com

I was exploring this because the structure contains variables declared
volatile. Thus
volatile int * const test;
But because the programm was not working correctly, I thought it had to do
with the object declared const. But I understand you explanation so this
part was correct, thanx.

nospam wrote:

> I have this struct typedef:

> typedef struct
> {
>         int * test;
> } testst;

> and have this declaration:

> const testst abc;

> What is constant? The pointer (like in: int * const test) or the
> integer (like in const int * test) or both?

Nothing.  You failed to initialize abc.  This is the only place you
can set its value.  F'ups set.

--
 <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
 <http://www.securityfocus.com/columnists/423>
 <http://www.aaxnet.com/editor/edit043.html>
 <http://kadaitcha.cx/vista/dogsbreakfast/index.html>
                        cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

nospam wrote:

> I have this struct typedef:

> typedef struct
> {
>         int * test;
> } testst;

> and have this declaration:

> const testst abc;

> What is constant? The pointer (like in: int * const test) or the
> integer (like in const int * test) or both?

Nothing.  You failed to initialize abc.  This is the only place you
can set its value.

--
 <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
 <http://www.securityfocus.com/columnists/423>
 <http://www.aaxnet.com/editor/edit043.html>
 <http://kadaitcha.cx/vista/dogsbreakfast/index.html>
                        cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

nospam wrote:

> I have this struct typedef:

> typedef struct
> {
>         int * test;
> } testst;

> and have this declaration:

> const testst abc;

> What is constant? The pointer (like in: int * const test) or the
> integer (like in const int * test) or both?

Nothing.  You failed to initialize abc.  This is the only place you
can set its value.  F'ups set.

--
 <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
 <http://www.securityfocus.com/columnists/423>
 <http://www.aaxnet.com/editor/edit043.html>
 <http://kadaitcha.cx/vista/dogsbreakfast/index.html>
                        cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

[restored attributions]

Milux wrote:
> Mike Wahler wrote:

>> What specifically are you trying to do?  Write
>> code for a particular task, or understand something
>> written by someone else?

> I was exploring this because the structure contains variables declared
> volatile. Thus
> volatile int * const test;
> But because the programm was not working correctly, I thought it had
> to do with the object declared const. But I understand you explanation
> so this part was correct, thanx.

While exploring this, you should be aware that 'const' is actually very
badly named.
The effect of const-qualifying something is only to mark it as
read-only. It does not make it constant/unchangeable.

For example, on machines that allow direct access to (memory mapped)
hardware, you could have something like this
  const volatile int * const current_time = (const volatile int*)0x1234;
to gain access to a hardware timer.
Through the variable current_time, you are allowed to read the current
value of the timer, but you can not modify it from within the program.
Obviously, the value you read will differ over time.

>> -Mike

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc