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


Groups > comp.lang.c > #89265 > unrolled thread

how does one access a specific address location in C?

Started byG G <gdotone@gmail.com>
First post2016-06-16 06:32 -0700
Last post2016-06-19 00:34 -0500
Articles 20 on this page of 38 — 13 participants

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


Contents

  how does one access a specific address location in C? G G <gdotone@gmail.com> - 2016-06-16 06:32 -0700
    Re: how does one access a specific address location in C? gazelle@shell.xmission.com (Kenny McCormack) - 2016-06-16 14:00 +0000
    Re: how does one access a specific address location in C? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-06-16 15:07 +0100
      Re: how does one access a specific address location in C? G G <gdotone@gmail.com> - 2016-06-16 07:18 -0700
        Re: how does one access a specific address location in C? Robert Wessel <robertwessel2@yahoo.com> - 2016-06-16 11:38 -0500
    Re: how does one access a specific address location in C? Mark Storkamp <mstorkamp@yahoo.com> - 2016-06-16 09:16 -0500
      Re: how does one access a specific address location in C? G G <gdotone@gmail.com> - 2016-06-16 07:50 -0700
        Re: how does one access a specific address location in C? G G <gdotone@gmail.com> - 2016-06-16 08:04 -0700
          Re: how does one access a specific address location in C? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-06-16 17:03 +0100
            Re: how does one access a specific address location in C? G G <gdotone@gmail.com> - 2016-06-16 10:01 -0700
              Re: how does one access a specific address location in C? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-16 14:29 -0400
              Re: how does one access a specific address location in C? Mark Storkamp <mstorkamp@yahoo.com> - 2016-06-16 13:34 -0500
                Re: how does one access a specific address location in C? BartC <bc@freeuk.com> - 2016-06-16 19:57 +0100
                  Re: how does one access a specific address location in C? raltbos@xs4all.nl (Richard Bos) - 2016-06-18 20:50 +0000
                  Re: how does one access a specific address location in C? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-18 17:23 -0400
                    Re: how does one access a specific address location in C? raltbos@xs4all.nl (Richard Bos) - 2016-06-18 21:30 +0000
              Re: how does one access a specific address location in C? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-06-16 21:09 +0100
          Re: how does one access a specific address location in C? Mark Storkamp <mstorkamp@yahoo.com> - 2016-06-16 11:10 -0500
        Re: how does one access a specific address location in C? James Kuyper <jameskuyper@verizon.net> - 2016-06-16 13:41 -0400
          Re: how does one access a specific address location in C? G G <gdotone@gmail.com> - 2016-06-16 11:14 -0700
            Re: how does one access a specific address location in C? Keith Thompson <kst-u@mib.org> - 2016-06-16 11:26 -0700
            Re: how does one access a specific address location in C? James Kuyper <jameskuyper@verizon.net> - 2016-06-16 16:38 -0400
        Re: how does one access a specific address location in C? "James R. Kuyper" <jameskuyper@verizon.net> - 2016-06-18 11:32 -0400
    Re: how does one access a specific address location in C? James Kuyper <jameskuyper@verizon.net> - 2016-06-16 12:45 -0400
      Re: how does one access a specific address location in C? G G <gdotone@gmail.com> - 2016-06-16 10:19 -0700
      Re: how does one access a specific address location in C? Keith Thompson <kst-u@mib.org> - 2016-06-16 11:20 -0700
      Re: how does one access a specific address location in C? supercat@casperkitty.com - 2016-06-16 11:38 -0700
        Re: how does one access a specific address location in C? raltbos@xs4all.nl (Richard Bos) - 2016-06-18 13:19 +0000
          Re: how does one access a specific address location in C? supercat@casperkitty.com - 2016-06-18 07:11 -0700
            Re: how does one access a specific address location in C? Robert Wessel <robertwessel2@yahoo.com> - 2016-06-18 14:41 -0500
              Re: how does one access a specific address location in C? supercat@casperkitty.com - 2016-06-18 16:02 -0700
                Re: how does one access a specific address location in C? Les Cargill <lcargill99@comcast.com> - 2016-06-18 18:53 -0500
                  Re: how does one access a specific address location in C? supercat@casperkitty.com - 2016-06-18 17:31 -0700
                    Re: how does one access a specific address location in C? Les Cargill <lcargill99@comcast.com> - 2016-06-19 06:47 -0500
                  Re: how does one access a specific address location in C? Robert Wessel <robertwessel2@yahoo.com> - 2016-06-19 00:37 -0500
                    Re: how does one access a specific address location in C? BartC <bc@freeuk.com> - 2016-06-19 11:07 +0100
                      Re: how does one access a specific address location in C? Robert Wessel <robertwessel2@yahoo.com> - 2016-06-19 16:21 -0500
                Re: how does one access a specific address location in C? Robert Wessel <robertwessel2@yahoo.com> - 2016-06-19 00:34 -0500

Page 1 of 2  [1] 2  Next page →


#89265 — how does one access a specific address location in C?

FromG G <gdotone@gmail.com>
Date2016-06-16 06:32 -0700
Subjecthow does one access a specific address location in C?
Message-ID<994e7598-1570-4931-8cee-d5a7abb967a5@googlegroups.com>
how does one access a specific address location?

given address say:  0x00000002

given the value at that location is an int, 32 bits in size.


------

given address say: 0x00000006

given the value at that location in a char, 16 bits in size.

------

Please explain the thought process of addressing a specific address
location.

Or/And is it a hack(so to speak) to do so, or does the specification support such a use
of the C language.

so, not the following

...

   int aNumber;

   int *aNumberPtr;

   aNumber = 5;

   aNumberPtr = &aNumber;

....

but were we are told the location in memory we must look at
that the type of object in that location.

thanks everyone,

g.

[toc] | [next] | [standalone]


#89268

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2016-06-16 14:00 +0000
Message-ID<njubds$glg$1@news.xmission.com>
In reply to#89265
In article <994e7598-1570-4931-8cee-d5a7abb967a5@googlegroups.com>,
G G  <gdotone@gmail.com> wrote:
>how does one access a specific address location?
>
>given address say:  0x00000002
>
>given the value at that location is an int, 32 bits in size.

The short answer is that you can't talk about that here.

IOW, ...

    Off topic.  Not portable.  Cant discuss it here.  Blah, blah, blah.

-- 
Useful clc-related links:

    http://en.wikipedia.org/wiki/Aspergers
    http://en.wikipedia.org/wiki/Clique
    http://en.wikipedia.org/wiki/C_programming_language

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


#89270

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-06-16 15:07 +0100
Message-ID<878ty5w7ku.fsf@bsb.me.uk>
In reply to#89265
G G <gdotone@gmail.com> writes:

> how does one access a specific address location?
>
> given address say:  0x00000002
>
> given the value at that location is an int, 32 bits in size.

  *(int *)2

will treat 2 as a pointer to an int and give you the int found there.
It won't always work (you may not have permission or 2 might not be a
properly aligned address for an int and so on) but it's about the best
you can do.

> ------
>
> given address say: 0x00000006
>
> given the value at that location in a char, 16 bits in size.

Do you mean "is a char"?  *(char *)6 would be a start, but is char really
16 bits on your target system?

<snip>
-- 
Ben.

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


#89273

FromG G <gdotone@gmail.com>
Date2016-06-16 07:18 -0700
Message-ID<8302cced-1072-4cd8-97ce-e638206e3da8@googlegroups.com>
In reply to#89270
On Thursday, June 16, 2016 at 10:07:35 AM UTC-4, Ben Bacarisse wrote:
> G G <gdotone@gmail.com> writes:
> 
> > how does one access a specific address location?
> >
> > given address say:  0x00000002
> >
> > given the value at that location is an int, 32 bits in size.
> 
>   *(int *)2
> 
> will treat 2 as a pointer to an int and give you the int found there.
> It won't always work (you may not have permission or 2 might not be a
> properly aligned address for an int and so on) but it's about the best
> you can do.
> 
> > ------
> >
> > given address say: 0x00000006
> >
> > given the value at that location in a char, 16 bits in size.
> 
> Do you mean "is a char"?  *(char *)6 would be a start, but is char really
> 16 bits on your target system?

thanks Ben, there is no target system, not an actual system here.
so, no 16 bits char on a target system.

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


#89303

FromRobert Wessel <robertwessel2@yahoo.com>
Date2016-06-16 11:38 -0500
Message-ID<vcl5mbhfcn634e78ij74jr9ov1cump0sm4@4ax.com>
In reply to#89273
On Thu, 16 Jun 2016 07:18:54 -0700 (PDT), G G <gdotone@gmail.com>
wrote:

>On Thursday, June 16, 2016 at 10:07:35 AM UTC-4, Ben Bacarisse wrote:
>> G G <gdotone@gmail.com> writes:
>> 
>> > how does one access a specific address location?
>> >
>> > given address say:  0x00000002
>> >
>> > given the value at that location is an int, 32 bits in size.
>> 
>>   *(int *)2
>> 
>> will treat 2 as a pointer to an int and give you the int found there.
>> It won't always work (you may not have permission or 2 might not be a
>> properly aligned address for an int and so on) but it's about the best
>> you can do.
>> 
>> > ------
>> >
>> > given address say: 0x00000006
>> >
>> > given the value at that location in a char, 16 bits in size.
>> 
>> Do you mean "is a char"?  *(char *)6 would be a start, but is char really
>> 16 bits on your target system?
>
>thanks Ben, there is no target system, not an actual system here.
>so, no 16 bits char on a target system.


Then there is no answer - those types of operations, if defined at
all, are completely specific to an implementation.

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


#89272

FromMark Storkamp <mstorkamp@yahoo.com>
Date2016-06-16 09:16 -0500
Message-ID<mstorkamp-017076.09162116062016@88-209-239-213.giganet.hu>
In reply to#89265
In article <994e7598-1570-4931-8cee-d5a7abb967a5@googlegroups.com>,
 G G <gdotone@gmail.com> wrote:

> how does one access a specific address location?
> 
> given address say:  0x00000002
> 
> given the value at that location is an int, 32 bits in size.

That's comp.lang.c faq question 19.25

http://c-faq.com/osdep/rawmemadr.html

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


#89277

FromG G <gdotone@gmail.com>
Date2016-06-16 07:50 -0700
Message-ID<482fe8e7-a95e-4579-8baf-90565a1530e9@googlegroups.com>
In reply to#89272
On Thursday, June 16, 2016 at 10:16:31 AM UTC-4, Mark Storkamp wrote:
> In article <994e7598-1570-4931-8cee-d5a7abb967a5@googlegroups.com>,
>  G G <gdotone@gmail.com> wrote:
> 
> > how does one access a specific address location?
> > 
> > given address say:  0x00000002
> > 
> > given the value at that location is an int, 32 bits in size.
> 
> That's comp.lang.c faq question 19.25
> 
> http://c-faq.com/osdep/rawmemadr.html


thanks Mark.

given :

   int aNumber; 

   int *aNumberPtr; 

   aNumber = 5; 

   aNumberPtr = &aNumber; 

----

if one wanted to look at memory location at &aNumber.

the following is suppose to work?

unsigned int *peekAtValuePtr = ( unsigned int *) 0x7fff5f01bc1c

printf( "The value at this location in memory %d", (int) *peekAtValuePtr );

----------------

#include <stdio.h>

int main( void )
{
   int a;
   int *aPtr;

   a = 7;
   aPtr = &a;

   printf( "The address of a is %p"
           "\nThe value of aPtr is %p", &a, aPtr );


   printf( "\n\nThe value of a is %d"
           "\nThe value of *aPtr is %d", a, *aPtr );

   printf( "\n\nShowing that * and & are complements of "
           "each other\n&*Ptr = %p"
           "\n*&aPtr = %p\n", &*aPtr, *&aPtr );

   unsigned int *peekAtValuePtr = (unsigned int *) 0x7fff5596ec1c; // address of a on my machine

   printf( "The value at this location in memory is %d", (int) *peekAtValuePtr );


} // end main

that does give me the value at that address. 

Thanks Mark and Ben,

g.

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


#89278

FromG G <gdotone@gmail.com>
Date2016-06-16 08:04 -0700
Message-ID<1a8af5ff-56b1-42a5-972f-20e44e573c63@googlegroups.com>
In reply to#89277
On Thursday, June 16, 2016 at 10:50:26 AM UTC-4, G G wrote:
> On Thursday, June 16, 2016 at 10:16:31 AM UTC-4, Mark Storkamp wrote:
> > In article <994e7598-1570-4931-8cee-d5a7abb967a5@googlegroups.com>,
> >  G G <gdotone@gmail.com> wrote:
> > 
> > > how does one access a specific address location?
> > > 
> > > given address say:  0x00000002
> > > 
> > > given the value at that location is an int, 32 bits in size.
> > 
> > That's comp.lang.c faq question 19.25
> > 
> > http://c-faq.com/osdep/rawmemadr.html
> 
> 
> thanks Mark.
> 
> given :
> 
>    int aNumber; 
> 
>    int *aNumberPtr; 
> 
>    aNumber = 5; 
> 
>    aNumberPtr = &aNumber; 
> 
> ----
> 
> if one wanted to look at memory location at &aNumber.
> 
> the following is suppose to work?
> 
> unsigned int *peekAtValuePtr = ( unsigned int *) 0x7fff5f01bc1c
> 
> printf( "The value at this location in memory %d", (int) *peekAtValuePtr );
> 
> ----------------
> 
> #include <stdio.h>
> 
> int main( void )
> {
>    int a;
>    int *aPtr;
> 
>    a = 7;
>    aPtr = &a;
> 
>    printf( "The address of a is %p"
>            "\nThe value of aPtr is %p", &a, aPtr );
> 
> 
>    printf( "\n\nThe value of a is %d"
>            "\nThe value of *aPtr is %d", a, *aPtr );
> 
>    printf( "\n\nShowing that * and & are complements of "
>            "each other\n&*Ptr = %p"
>            "\n*&aPtr = %p\n", &*aPtr, *&aPtr );
> 
>    unsigned int *peekAtValuePtr = (unsigned int *) 0x7fff5596ec1c; // address of a on my machine
> 
>    printf( "The value at this location in memory is %d", (int) *peekAtValuePtr );
> 
> 
> } // end main
> 
> that does give me the value at that address. 
> 

It gives me a segmentation fault:  11

i think this is what Ben was explaining?
... It won't always work (you may not have permission or 2 might not be a 
properly aligned address for an int and so on) ...

> Thanks Mark and Ben,
> 
> g.

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


#89294

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-06-16 17:03 +0100
Message-ID<87shwdunmh.fsf@bsb.me.uk>
In reply to#89278
G G <gdotone@gmail.com> writes:

> On Thursday, June 16, 2016 at 10:50:26 AM UTC-4, G G wrote:
<snip>
>> #include <stdio.h>
>> 
>> int main( void )
>> {
>>    int a;
>>    int *aPtr;
>> 
>>    a = 7;
>>    aPtr = &a;
>> 
>>    printf( "The address of a is %p"
>>            "\nThe value of aPtr is %p", &a, aPtr );

Technically, you need to cast these pointers to void *.  %p expects a
void * but you probably won't ever use a machine where this matters.

>>    printf( "\n\nThe value of a is %d"
>>            "\nThe value of *aPtr is %d", a, *aPtr );
>> 
>>    printf( "\n\nShowing that * and & are complements of "
>>            "each other\n&*Ptr = %p"
>>            "\n*&aPtr = %p\n", &*aPtr, *&aPtr );

Ditto.

>>    unsigned int *peekAtValuePtr = (unsigned int *) 0x7fff5596ec1c; //
>>    address of a on my machine

Why unsigned int?  Later you want an int.  It may not matter much in
this case but why mess about with the types?

>>    printf( "The value at this location in memory is %d", (int) *peekAtValuePtr );

There is no need for this cast.

>> } // end main
>> 
>> that does give me the value at that address. 
>> 
>
> It gives me a segmentation fault:  11

When I run this program, the address of a changes each time so I can't
"hard wire" it into the program.  Are you sure you are not getting the
same effect?  It would help if you posted the output.

<snip>
-- 
Ben.

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


#89305

FromG G <gdotone@gmail.com>
Date2016-06-16 10:01 -0700
Message-ID<849b7311-65f7-4df2-8750-c94c2407823f@googlegroups.com>
In reply to#89294
On Thursday, June 16, 2016 at 12:03:56 PM UTC-4, Ben Bacarisse wrote:
> G G <gdotone@gmail.com> writes:
> 
> > On Thursday, June 16, 2016 at 10:50:26 AM UTC-4, G G wrote:
> <snip>
> >> #include <stdio.h>
> >> 
> >> int main( void )
> >> {
> >>    int a;
> >>    int *aPtr;
> >> 
> >>    a = 7;
> >>    aPtr = &a;
> >> 
> >>    printf( "The address of a is %p"
> >>            "\nThe value of aPtr is %p", &a, aPtr );
> 
> Technically, you need to cast these pointers to void *.  %p expects a
> void * but you probably won't ever use a machine where this matters.
> 
> >>    printf( "\n\nThe value of a is %d"
> >>            "\nThe value of *aPtr is %d", a, *aPtr );
> >> 
> >>    printf( "\n\nShowing that * and & are complements of "
> >>            "each other\n&*Ptr = %p"
> >>            "\n*&aPtr = %p\n", &*aPtr, *&aPtr );
> 
> Ditto.
> 
> >>    unsigned int *peekAtValuePtr = (unsigned int *) 0x7fff5596ec1c; //
> >>    address of a on my machine
> 
> Why unsigned int?  Later you want an int.  It may not matter much in
> this case but why mess about with the types?
> 
> >>    printf( "The value at this location in memory is %d", (int) *peekAtValuePtr );
> 
> There is no need for this cast.
> 
> >> } // end main
> >> 
> >> that does give me the value at that address. 
> >> 
> >
> > It gives me a segmentation fault:  11
> 
> When I run this program, the address of a changes each time so I can't
> "hard wire" it into the program.  Are you sure you are not getting the
> same effect?  It would help if you posted the output.
> 
> <snip>
> -- 
> Ben.

Ben you are right the address does change. I guess it was just a fluke 
to have the same address produced on two separate runs.

> >>    unsigned int *peekAtValuePtr = (unsigned int *) 0x7fff5596ec1c; //
> >>    address of a on my machine
> 
> Why unsigned int?  Later you want an int.  It may not matter much in
> this case but why mess about with the types?

i was following the example given from
comp.lang.c faq question 19.25 http://c-faq.com/osdep/rawmemadr.html

the (int) *peekAtValuePtr casting was only added to try to get rid
of the segmentation fault:11 it didn't help.

there just has to be a way of looking at a memory location 
given the location, doesn't it?

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


#89319

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-06-16 14:29 -0400
Message-ID<njur7b$3h6$1@dont-email.me>
In reply to#89305
On 6/16/2016 1:01 PM, G G wrote:
> [...]
> there just has to be a way of looking at a memory location
> given the location, doesn't it?

     Yes -- if you are "given the location" as a pointer value.

     If you are "given the location" in some other form -- perhaps
as an integer with a system-specific meaning, or as an ordered
pair like (privilegeRing,accessIdentifier), or as something else --
then the C implementation on that system might provide a way to
translate that form into a pointer value, and then you're off to
the races.  But both the form and the translation are tied to that
specific implementation, or (with luck and a following wind) to a
family of related implementations.

     ... which is usually just fine, because when you're told
something like "To activate the SuperEncryptorChip write a sequence
of command words (see Figure 4) to location 0xA800:0x18770, then
read location 0xA800:0x18778 to obtain the results," that information
is pretty tightly tied to a specific implementation anyhow.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

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


#89320

FromMark Storkamp <mstorkamp@yahoo.com>
Date2016-06-16 13:34 -0500
Message-ID<mstorkamp-FBA0CC.13344316062016@88-209-239-213.giganet.hu>
In reply to#89305
In article <849b7311-65f7-4df2-8750-c94c2407823f@googlegroups.com>,
 G G <gdotone@gmail.com> wrote:

> there just has to be a way of looking at a memory location 
> given the location, doesn't it?

Short answer: no.

In the nascent days of home computers security wasn't much of an issue, 
and only one program typically ran at a time, so all of the available 
memory was given to the program that was running. Unless you're 
programming for an embedded controller, those days are pretty much over. 
Even the operating system doesn't have access to all memory. I'm not 
sure of the latest practice, but I remember when Intel introduced a 
supervisor mode that would get initialized by the BIOS and run above the 
OS. The supervisor has access to an area of memory that's hidden from 
the rest of the system.

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


#89323

FromBartC <bc@freeuk.com>
Date2016-06-16 19:57 +0100
Message-ID<njusr1$9e3$1@dont-email.me>
In reply to#89320
On 16/06/2016 19:34, Mark Storkamp wrote:
> In article <849b7311-65f7-4df2-8750-c94c2407823f@googlegroups.com>,
>  G G <gdotone@gmail.com> wrote:
>
>> there just has to be a way of looking at a memory location
>> given the location, doesn't it?
>
> Short answer: no.
>
> In the nascent days of home computers security wasn't much of an issue,
> and only one program typically ran at a time, so all of the available
> memory was given to the program that was running. Unless you're
> programming for an embedded controller, those days are pretty much over.
> Even the operating system doesn't have access to all memory. I'm not
> sure of the latest practice, but I remember when Intel introduced a
> supervisor mode that would get initialized by the BIOS and run above the
> OS. The supervisor has access to an area of memory that's hidden from
> the rest of the system.
>

Instead you have access to the virtual memory locations in your program. 
Although not all addresses may be set up to point to actual memory, so 
you need to know what's what.

On my Windows machine, I can access location 0x400000, but not 03ffffff.

But I can also allocate memory and make those raw locations known:

#define N 1024
int memory[N];

int main(void) {
     printf("Memory limits: %p to %p\n",&memory[0],&memory[N-1]);
}

This might show:

  Memory limits: 00405420 to 0040641C

(actually to 40641F inclusive)

and those actual addresses can be peeked and poked during the same 
invocation of the program.

-- 
Bartc

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


#89568

Fromraltbos@xs4all.nl (Richard Bos)
Date2016-06-18 20:50 +0000
Message-ID<5765b29f.31894843@news.xs4all.nl>
In reply to#89323
BartC <bc@freeuk.com> wrote:

> On my Windows machine, I can access location 0x400000, but not 03ffffff.
> 
> But I can also allocate memory and make those raw locations known:
> 
> #define N 1024
> int memory[N];
> 
> int main(void) {
>      printf("Memory limits: %p to %p\n",&memory[0],&memory[N-1]);
> }
> 
> This might show:
> 
>   Memory limits: 00405420 to 0040641C
> 
> (actually to 40641F inclusive)
> 
> and those actual addresses can be peeked and poked during the same 
> invocation of the program.

Sure, but that's pretty useless. You already know that those addresses
are memory to memory+N-1, and those designations will remain valid even
if you run the program again or include it in a larger one, while the
"actual" numerical addresses may change between any two invocations.
So yes, you _can_ "poke" those numerical addresses, but it's actually
easier not to.
When people ask how to "poke" numerical addresses in C, they usually
want to write to an address that is _not_ their own, and for which they
do not have a symbolic name but for which they (think they!) do have a
number like 0x00000002. Your technique, though it works, does not solve
that problem. (And in fact, it's a problem for which the general case
cannot be solved, as explained fully in the rest of this thread.)

Richard

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


#89572

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-06-18 17:23 -0400
Message-ID<nk4e3s$s79$2@dont-email.me>
In reply to#89323
On 6/16/2016 2:57 PM, BartC wrote:
> [...]
> On my Windows machine, I can access location 0x400000, but not 03ffffff.

     That's because Windows is a bollocks-scoped tree.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

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


#89573

Fromraltbos@xs4all.nl (Richard Bos)
Date2016-06-18 21:30 +0000
Message-ID<5765bd74.34667718@news.xs4all.nl>
In reply to#89572
Eric Sosman <esosman@comcast-dot-net.invalid> wrote:

> On 6/16/2016 2:57 PM, BartC wrote:
> > [...]
> > On my Windows machine, I can access location 0x400000, but not 03ffffff.
> 
>      That's because Windows is a bollocks-scoped tree.

...nnn....oooo.

No, neither premise nor conclusion is warranted.

Richard

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


#89334

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-06-16 21:09 +0100
Message-ID<87h9csvqsx.fsf@bsb.me.uk>
In reply to#89305
G G <gdotone@gmail.com> writes:
<snip>
> there just has to be a way of looking at a memory location 
> given the location, doesn't it?

If the address is valid, yes there is.  What part of the explanation
here or in the FAQ are you having trouble with?

-- 
Ben.

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


#89298

FromMark Storkamp <mstorkamp@yahoo.com>
Date2016-06-16 11:10 -0500
Message-ID<mstorkamp-67D7DE.11100016062016@88-209-239-213.giganet.hu>
In reply to#89278
In article <1a8af5ff-56b1-42a5-972f-20e44e573c63@googlegroups.com>,
 G G <gdotone@gmail.com> wrote:

> 
> It gives me a segmentation fault:  11
> 
> i think this is what Ben was explaining?
> ... It won't always work (you may not have permission or 2 might not be a 
> properly aligned address for an int and so on) ...
> 

From the previously mentioned faq:

"Many operating systems execute user-mode programs in a protected mode 
where direct access to I/O devices (or to any address outside the 
running process) is simply not possible. In such cases you will have to 
ask the operating system to carry out I/O operations for you."

I get a bus error on OSX, but I know it worked with DOS 3.11. (a bit 
more to it with DOS since you had a segment:offset memory scheme to deal 
with)

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


#89311

FromJames Kuyper <jameskuyper@verizon.net>
Date2016-06-16 13:41 -0400
Message-ID<njuobq$oft$1@dont-email.me>
In reply to#89277
On 06/16/2016 10:50 AM, G G wrote:
...
> given :
> 
>    int aNumber; 
> 
>    int *aNumberPtr; 
> 
>    aNumber = 5; 
> 
>    aNumberPtr = &aNumber; 
> 
> ----
> 
> if one wanted to look at memory location at &aNumber.
> 
> the following is suppose to work?
> 
> unsigned int *peekAtValuePtr = ( unsigned int *) 0x7fff5f01bc1c

Only if aNumber happens to be located at that address,. What you should
be doing is

    int *peekAtValuePtr = &aNumber;

Is there some reason why that's not an acceptable answer to your question?

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


#89313

FromG G <gdotone@gmail.com>
Date2016-06-16 11:14 -0700
Message-ID<da2ba18e-0823-4883-a4be-66bd748d14f0@googlegroups.com>
In reply to#89311
On Thursday, June 16, 2016 at 1:41:21 PM UTC-4, James Kuyper wrote:
> On 06/16/2016 10:50 AM, G G wrote:
> ...
> > given :
> > 
> >    int aNumber; 
> > 
> >    int *aNumberPtr; 
> > 
> >    aNumber = 5; 
> > 
> >    aNumberPtr = &aNumber; 
> > 
> > ----
> > 
> > if one wanted to look at memory location at &aNumber.
> > 
> > the following is suppose to work?
> > 
> > unsigned int *peekAtValuePtr = ( unsigned int *) 0x7fff5f01bc1c
> 
> Only if aNumber happens to be located at that address,. What you should
> be doing is
> 
>     int *peekAtValuePtr = &aNumber;
> 
> Is there some reason why that's not an acceptable answer to your question?

and that works, but no. my thinking was given an address to look at that address.
i needed an address that i knew i could write to, not restricted by the OS, but 
from running the program repeatedly, at least on my system, Ben is right, the 
address changes.

that kind of what started my curiosity because 

....

   int peekAtValuePtr = &aNumber;
  
   printf ( "the value at this address is %d", *peekAtValuePtr );
....
works fine.

but, no, i was thinking just starting with an address, where one
knew the object type, could the value be seen?

hm, so perhaps, as i was told earlier, i must not think in terms
of having the OS handle the I/O? just a general question, and
please if it is far a field ... i get it. how are devices controlled
on, for example, PCs.   aren't you writing to specific memory 
location? i'll find a book on device drivers, but if anyone has any 
recommendations i'm interested.

Thanks James,

g.

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web