Re: Convert Int Value To Pointer
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Fri, 14 Jul 2006 22:33:03 -0500
On Fri, 14 Jul 2006 19:37:20 GMT, Frederick Gotham
<fgothamNO@xxxxxxxx> wrote in comp.lang.c:
ReaperUnreal posted:
I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:
void *value = 0x00323c68;
but I get a typecasting error. If I do the following:
void *value = static_cast<void *>(0x00323c68);
will that get me what I desire?
How about something like the following?
#include <stddef.h>
#include <limits.h>
#include <stdio.h>
void PrintBits(void const * const mem, size_t amount_bytes)
{
char static str[CHAR_BIT + 1]; /* Auto null teminator */
unsigned char const *p = (unsigned char const *)mem;
do
{
unsigned char const byte_val = *p++;
char *pos = str;
unsigned char i = 1U << CHAR_BIT - 1;
do *pos++ = byte_val & i ? '1' : '0';
while(i >>= 1U);
Do you realize that there is absolutely no gain to adding the 'U'
suffix here?
printf("%s",str);
} while (--amount_bytes);
}
int main(void)
{
void * const p = (void*)0x00323c68;
PrintBits( p, 1 );
}
Do you actually this makes the behavior any less undefined? Do you do
realize that without a terminating '\n', there is no guarantee that
any output will appear?
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.
- Follow-Ups:
- Re: Convert Int Value To Pointer
- From: Frederick Gotham
- Re: Convert Int Value To Pointer
- References:
- Convert Int Value To Pointer
- From: ReaperUnreal
- Re: Convert Int Value To Pointer
- From: Frederick Gotham
- Convert Int Value To Pointer
- Prev by Date: Re: Where is a static variable stored?
- Next by Date: Re: Does malloc() reuse addresses?
- Previous by thread: Re: Convert Int Value To Pointer
- Next by thread: Re: Convert Int Value To Pointer
- Index(es):
Relevant Pages
|