<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>silly pointer question - C++ - tribe.net</title>
  <link rel="alternate" href="http://cpp.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4?format=atom" />
  <subtitle>Tribe.net. Local Connections</subtitle>
  <entry>
    <title>silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#11e2e238-c4ec-41a3-b9c3-a34bbdbdbe98" />
    <author>
      <name>StFiend</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#11e2e238-c4ec-41a3-b9c3-a34bbdbdbe98</id>
    <published>2004-02-18T23:05:03Z</published>
    <summary type="html">What's this do? I assume it crashes the app, if not the whole system, but knowing very little about memory architecture I could see it doing something weird like wipe my BIOS. So I'm afraid to compile it and find out. Oh, and tribe doesn't like my indents, sorry.&#xD;
&#xD;
void main()&#xD;
{&#xD;
 for (int x=0; 1; x++)&#xD;
  *x=0;&#xD;
}</summary>
    <dc:creator>StFiend</dc:creator>
    <dc:date>2004-02-18T23:05:03Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#f1516ab8-f3ba-4a90-8a6f-959f838a45bf" />
    <author>
      <name>StFiend</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#f1516ab8-f3ba-4a90-8a6f-959f838a45bf</id>
    <published>2004-02-18T23:08:23Z</published>
    <summary type="html">Or can I even use the reference operator with a variable not explicitly defined as a pointer? Obviously I've not yet done any serious C coding...</summary>
    <dc:creator>StFiend</dc:creator>
    <dc:date>2004-02-18T23:08:23Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#d3a8b58c-e65f-4a3f-bfff-3400af4955fb" />
    <author>
      <name>Genghis "Doh!"</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#d3a8b58c-e65f-4a3f-bfff-3400af4955fb</id>
    <published>2004-02-18T23:40:05Z</published>
    <summary type="html">You can't use an int as a pointer.  To work, it'd have to be something like:&#xD;
for (int x=0; 1; x++) &#xD;
{&#xD;
	char *loc = (char*)x;&#xD;
	*loc=0; &#xD;
}&#xD;
&#xD;
As to what it's do, depends on the operating system.  Might crash or hang Win 95/98/Me but NT variants and UNIX/Linux variants wil protect OS memory.</summary>
    <dc:creator>Genghis "Doh!"</dc:creator>
    <dc:date>2004-02-18T23:40:05Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#5f38b319-3637-40e8-9a28-dacbc7448c8f" />
    <author>
      <name>Chris</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#5f38b319-3637-40e8-9a28-dacbc7448c8f</id>
    <published>2004-02-19T03:47:18Z</published>
    <summary type="html">why wouldn't that give a syntax error or a trivial reassignment depending upon compiler?  you are just dereferencing the memory location of variable "x" right?  &#xD;
&#xD;
and even if it doesn't, I could see:&#xD;
&#xD;
&amp;amp;x = 0; &#xD;
&#xD;
which would should take the memory space for "x" and set it to NULL while it should still be storing a value, and that I could see would give a segfault.  Kind of curious, its stuff like this that makes C/C++ mystifying, so any input would be much appreciated.</summary>
    <dc:creator>Chris</dc:creator>
    <dc:date>2004-02-19T03:47:18Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#2caadcfc-b5b4-44b1-a546-8bd0b91e38c9" />
    <author>
      <name>Genghis "Doh!"</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#2caadcfc-b5b4-44b1-a546-8bd0b91e38c9</id>
    <published>2004-02-19T04:00:10Z</published>
    <summary type="html">I got an illegal indirection error from Visual Studio, wouldn't even compile.&#xD;
&#xD;
The "&amp;amp;x = 0" results in "left operand must be l-value" error.  l-value refers to the left side of an equation.  Not sure if that's ANSII C++ or a Microsoft improvisation.&#xD;
&#xD;
Maybe because you're trying to alter the location of a real variable whose space was allocated by the compiler/loader and&#xD;
not just change the pointer...</summary>
    <dc:creator>Genghis "Doh!"</dc:creator>
    <dc:date>2004-02-19T04:00:10Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#92d4c59d-5b2d-4dc9-8b8a-bb2361c8bd5f" />
    <author>
      <name>Chris</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#92d4c59d-5b2d-4dc9-8b8a-bb2361c8bd5f</id>
    <published>2004-02-19T08:12:41Z</published>
    <summary type="html">well, as I was walking home, I realized the real villain was :&#xD;
&#xD;
for(int x=0; 1; x++)&#xD;
&#xD;
didn't realize what that "1" would do for a little bit.  Now I see more of the problem.  &#xD;
&#xD;
I think the l-value is ANSI, and it makes sense, you aren't allowed to reassign registers to fixed variables.  So all is right with the world.  still though, I am curious, why would :&#xD;
&#xD;
for(int x=0; 1; i++)&#xD;
*x=0;&#xD;
&#xD;
cause any problem? aside from the infinite loop that would kick in that is?</summary>
    <dc:creator>Chris</dc:creator>
    <dc:date>2004-02-19T08:12:41Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#7ea1eb15-9278-40b5-935a-1fbfcf5b963e" />
    <author>
      <name>Genghis "Doh!"</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#7ea1eb15-9278-40b5-935a-1fbfcf5b963e</id>
    <published>2004-02-19T14:02:43Z</published>
    <summary type="html">&gt;for(int x=0; 1; i++) &#xD;
&gt;  *x=0; &#xD;
&gt;&#xD;
&gt;cause any problem? aside from the infinite loop that would &gt;kick in that is? &#xD;
&#xD;
Because you can only use the indirection operator "*" on pointer data types.  You can change the location that a pointer references but you can't change the location that a non-pointer references.&#xD;
&#xD;
   Don</summary>
    <dc:creator>Genghis "Doh!"</dc:creator>
    <dc:date>2004-02-19T14:02:43Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#b25d2889-224f-4538-8b7e-ef21872261f2" />
    <author>
      <name>StFiend</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#b25d2889-224f-4538-8b7e-ef21872261f2</id>
    <published>2004-02-19T17:16:15Z</published>
    <summary type="html">Gah, and I thought I was starting to grok pointers.&#xD;
&#xD;
At least my question turned out to be nontrivial...</summary>
    <dc:creator>StFiend</dc:creator>
    <dc:date>2004-02-19T17:16:15Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#c1598cae-cadd-4ecb-bae8-96e9e0e26fef" />
    <author>
      <name>Chris</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#c1598cae-cadd-4ecb-bae8-96e9e0e26fef</id>
    <published>2004-02-19T17:21:07Z</published>
    <summary type="html">look up Kernighan and Ritchie online, it should be free.  if I remember correctly, they have some horrific examples of pointer expressions that if you can figure out help in making sense of them.</summary>
    <dc:creator>Chris</dc:creator>
    <dc:date>2004-02-19T17:21:07Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#19eff743-3fb0-4a26-9603-6e3f17f44e46" />
    <author>
      <name>Genghis "Doh!"</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#19eff743-3fb0-4a26-9603-6e3f17f44e46</id>
    <published>2004-02-19T17:25:26Z</published>
    <summary type="html">Another thing could is to take an Assembly Language Programming class.  Getting down to the raw bits and bytes and working with different reference modes is a big help in groking what's going on.&#xD;
&#xD;
And the debugger is your friend.</summary>
    <dc:creator>Genghis "Doh!"</dc:creator>
    <dc:date>2004-02-19T17:25:26Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#1b5b40b0-b7b3-43b9-8159-119683cbc199" />
    <author>
      <name>Genghis "Doh!"</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#1b5b40b0-b7b3-43b9-8159-119683cbc199</id>
    <published>2004-02-19T17:37:22Z</published>
    <summary type="html">BTW, I was curious whether a different error would be thrown at address 0x0 than, say, at 0x5000 because NT variants tend to use the first chunk (1024 or 2048 bytes, I think) of a process's virtual address space as kind of a canary in a coal mine:  they're never allocated legitimately and ANY attempt to read/write there will be an error automatically.&#xD;
&#xD;
But the error looks the same...</summary>
    <dc:creator>Genghis "Doh!"</dc:creator>
    <dc:date>2004-02-19T17:37:22Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#cee6bf70-8a3d-4a40-91a7-73267f460fa0" />
    <author>
      <name>StFiend</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#cee6bf70-8a3d-4a40-91a7-73267f460fa0</id>
    <published>2004-02-19T18:18:14Z</published>
    <summary type="html">That was actually what I was getting at with my question, wondering what the memory address values actually correspond to, practically speaking. Whether the addresses are absolute for the machine or relative to each process, that sort of thing. (Though the pointer education is handy too, of course.) Now what's this, you're saying my OS uses an entire megabyte per process on nothing at all? Why is that?</summary>
    <dc:creator>StFiend</dc:creator>
    <dc:date>2004-02-19T18:18:14Z</dc:date>
  </entry>
  <entry>
    <title>Re: silly pointer question</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#95f8dcaa-08b3-471b-8994-9a5d3a7f79f2" />
    <author>
      <name>Genghis "Doh!"</name>
    </author>
    <id>http://CPP.tribe.net/thread/75e909fa-6739-4fab-9d0c-e94d683f77d4#95f8dcaa-08b3-471b-8994-9a5d3a7f79f2</id>
    <published>2004-02-19T18:34:01Z</published>
    <summary type="html">It's OS specific.  Not that familiar with UNIX but this link leads to info about how some Windows variants map out your virtual address space.  Looks like it's the first 64k that you can't touch but that's virtual memory, not your machine's physical memory going to waste:&#xD;
http://tinyurl.com/2wm3y&#xD;
&#xD;
If you're interested, this one looks at how the loader and Windows run executables:&#xD;
http://tinyurl.com/at4w</summary>
    <dc:creator>Genghis "Doh!"</dc:creator>
    <dc:date>2004-02-19T18:34:01Z</dc:date>
  </entry>
</feed>



