Staredit Network > Forums > Technology & Computers > Topic: C++ Question
C++ Question
Jan 16 2008, 10:09 pm
By: fatimid08  

Jan 16 2008, 10:09 pm fatimid08 Post #1



I'm a bit confused as to the interpretation of the following snippet:

*somepointer++ = somevalue

Does it increment the pointer and then assigns the value to what it points to, or does it assign the value to what it points to and then increments it?



None.

Jan 16 2008, 10:24 pm Falkoner Post #2



somevalue will get the value of somepointer + 1.



None.

Jan 16 2008, 11:10 pm Laser Dude Post #3



I just tested it (it took 5 minutes). The compiler outputs an error because, quote "Test.cpp:7: error: invalid lvalue in assignment". Here's the code snippet I tested:

Code
#include<iostream>

int main()
{
    int x = 0;

    x++ = 2;

    std::cout << x << std::endl;
}




None.

Jan 16 2008, 11:46 pm fatimid08 Post #4



x should be a pointer to another variable, not just a variable, else it doesn't make sense (and doesn't work, from your experiences).

And Falkoner, what on earth are you trying to say? If it means what I think it means, it's horribly wrong (the right hand side of the expression gets something assigned to????), and if not, well you should change your wording. And if it was sarcasm or a joke, well it's not a funny one.



None.

Jan 16 2008, 11:48 pm Esponeo Post #5



Falkoner and Laser Dude are retards who don't know what the fuck they are talking about.

Quote
void main()
{
int value = 10;
int *pointer = &value;
cout << (*pointer);
*pointer++ = 4;
cout << (*pointer);
}

As far as I can tell the address in memory the pointer is aimed at is what is being increased by the ++. Which is exactly what should happen, check out this priority table:
http://paowang.com/blog/hufey/archives/010535.html

So its basically a horrible memory leak, you're altering some address in memory you don't know jack about.



None.

Jan 17 2008, 12:14 am fatimid08 Post #6



So it's assignment first, increment after. Thanks.

The code is actually looping through known memory in compression/decompression stuff I'm porting from C++ to VB.Net as part of the cross-os MPQ library I'm working on, so it's not some random memory.



None.

Jan 17 2008, 8:09 pm ShadowFlare Post #7



If ++ (or --) is after the variable name, it always takes effect after the statement executes. So if you use variablename++ in an expression, the value used in the expression is the value before the increment. If you have ++ (or --) before the variable name, then it does the operation before reading the value of the variable. For example:

x = 3;
y = 2 + x++;

After those two statements, x = 4 and y = 5 because x was incremented after the second statement finished. This is how the post-increment operator works (variable++). An example of the pre-increment operator (++variable):

x = 3;
y = 2 + ++x;

Same as before, x = 4 after the second statement, but this time y = 6 because x was incremented before the calculation.



None.

Jan 17 2008, 9:12 pm cheeze Post #8



Anyone who doesn't know what a pointer is should not be posting in this. Esponeo is right anyway.



None.

Jan 18 2008, 2:07 am ShadowFlare Post #9



Oh, there was one more thing I did forget to mention.

When using ++ (or --) with dereferenced pointers, it applies it to the pointer, not the memory location, unless you put the *variablename in parentheses and the ++ (or --) outside. For example,

*pointername++ increments pointername after the statement that used it; it does not increment *pointername. To increment *pointername this way, you must use (*pointername)++.

Yes, it can be kind of confusing, but that's just the way it is.

Post has been edited 1 time(s), last time on Jan 18 2008, 2:13 am by ShadowFlare.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[2026-7-18. : 2:27 am]
Symmetry -- https://staredit.net/topic/18903/ THE REVIEWS ARE HERE! "ok these are pretty good memes" - ssj9Kevin
[2026-7-17. : 2:58 pm]
Ultraviolet -- Symmetry
Symmetry shouted: Man I wish we had this tech back in the day when people played ums lmao
fr fr
[2026-7-17. : 2:39 am]
Symmetry -- Man I wish we had this tech back in the day when people played ums lmao
[2026-7-16. : 6:28 am]
NudeRaider -- EUD actions, specifically. The conditions remained. Today we can even have actions again, but they're all virtualized/whitelisted (not sure on the actual technical implementation) so you can only use them for specific intended purposed, not arbitrary code injections.
[2026-7-16. : 6:26 am]
NudeRaider -- I mean yes, maps - through EUDs - were theoretically able to do that as well, but that was patched quickly.
[2026-7-16. : 6:25 am]
NudeRaider -- Symmetry
Symmetry shouted: Ohhh imagine a SC map that could delete itself
not the map, the editor
[2026-7-16. : 2:28 am]
Symmetry -- I vaguely remember Voy doing some ACE back in the day, but I had no idea EUDs could do that kind of shit. I am very much catching up on the technology
[2026-7-16. : 2:28 am]
Symmetry -- Ohhh imagine a SC map that could delete itself
[2026-7-15. : 8:51 pm]
NudeRaider -- Symmetry
Symmetry shouted: NudeRaider Is EUD editor capable of writing shit onto the player's harddrive? That seems like it would be dangerous
yeah an editor that isn't allowed to write files sounds rather pointless, so I'd assume it can. Like most other programs too btw. and yes, obviously that's dangerous, but also kinda necessary. MS introduced that virtualization for exactly that reason.
[2026-7-15. : 4:10 am]
Ultraviolet -- I don't think so. I think they shut that shit down after 1.16, maybe even earlier
Please log in to shout.


Members Online: Moose, Symmetry