valid or not

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2004
Posts: 31
Reputation: Sukhbir is an unknown quantity at this point 
Solved Threads: 0
Sukhbir Sukhbir is offline Offline
Light Poster

valid or not

 
0
  #1
Aug 31st, 2004
consider the statement
++*p++
if it is valid then evaluate it.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: valid or not

 
0
  #2
Aug 31st, 2004
Hello,

I am no C++ genius, but

++*p++

Cannot be a statement by itself, as there is no ; to finish it.

I am trying to remember if *p is significant. I know that &p is... the address of the variable p. p++ is just an incrementor. But C++ has been a "variable first, then operator" type of language. cars++ people--

I think it is an error.

Christian
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 241
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: valid or not

 
0
  #3
Aug 31st, 2004
Increment the object pointed to by p, then increment the pointer p (point to the next object).
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. char text[] = "1b#", *p = text;
  6. printf("text = \"%s\", p(%p) = \"%s\", *p = '%c'\n", text, (void*)p, p, *p);
  7. ++*p++;
  8. printf("text = \"%s\", p(%p) = \"%s\", *p = '%c'\n", text, (void*)p, p, *p);
  9. return 0;
  10. }
  11.  
  12. /* my output
  13.   text = "1b#", p(0012FF88) = "1b#", *p = '1'
  14.   text = "2b#", p(0012FF89) = "b#", *p = 'b'
  15.   */
Really, this code is trivial to come up with on your own. At least give these a try.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: valid or not

 
0
  #4
Aug 31st, 2004
Hello,

I stand corrected. Reading another post in the forum, people apparently do use ++variable syntax. I always took the style of variable++ and went with it to avoid confusion.

So

++p would be valid.

++*p++ I think is a problem.

Christian
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 185
Reputation: Stack Overflow is an unknown quantity at this point 
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: valid or not

 
0
  #5
Sep 1st, 2004
You could say its valid, though it really all depends on how or why its used:

void pointTo(char **src, char *dst) {
	*src = dst;
}

int main() {
	char h[25];
	char *hello;

	pointTo(&hello, h);

	strcpy(h, "Hello world!");

	printf("%c\n", ++*hello++);

	return 0;
}

You could ask yourself, "Wow, how'd it come up with 'I'?", though its perfectly understandable. *hello++ is 'H', as the first letter of our string, though ++*hello++ moves our first letter 'H' one to the right, resulting in the next letter of the alphabet, 'I'.


Hope this makes sense,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.

IRC
Channel: irc.daniweb.com
Room: #c, #shell
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 22
Reputation: Decency is an unknown quantity at this point 
Solved Threads: 1
Decency Decency is offline Offline
Newbie Poster

Re: valid or not

 
0
  #6
Sep 1st, 2004
hello, well this is valid in C++ but you may try to do it in separate statements or store the results in separate pointers just to avoid the logical errors that might occur, always remember flexibility comes before simplisity
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 24
Reputation: XianBin is an unknown quantity at this point 
Solved Threads: 0
XianBin XianBin is offline Offline
Newbie Poster

Re: valid or not

 
0
  #7
Sep 5th, 2004
Yeah,it is hard to konw.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC