|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I have some codes:
w_char **sFieldsUri; sFieldsUri = &(new w_char[2]); w_char **sValFind = nsnull; sValFind = &(new w_char[2]); When I debug my program, I found the above code had some strange things. sFieldsUri+1 is equal to sValFind+0. But if I change the codes to the following: w_char **sFieldsUri; sFieldsUri = &(new w_char[2]); for(int i=0; i<2; i++) { sFieldsUri[i] = new w_char[100]; } w_char **sValFind = nsnull; sValFind = &(new w_char[2]); for(int i=0; i<2; i++) { sVal Find[i] = new w_char[100]; } sFieldsUri+0, sFieldsUri+1, and sValFind+0, sValFind+1 are all difference. Thanks for all. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
DDD said:
> I have some codes: > w_char **sFieldsUri; > sFieldsUri = &(new w_char[2]); The language rules for C and C++ differ. I suggest you ask this C++ question in comp.lang.c++ for best results. -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
DDD wrote:
> I have some codes: > w_char **sFieldsUri; > sFieldsUri = &(new w_char[2]); ^^^^^^^^^ This tells us that you are in the wrong place, since that is a syntax error in C. Try posting to a newsgroup for whatever language you are using. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
DDD <1983ddd@gmail.com> wrote:
> I have some codes: > w_char **sFieldsUri; > sFieldsUri = &(new w_char[2]); This is not C, but (probably!) C++. Pointer handling in C and C++ are sufficiently different that you should ask this in comp.lang.c++, because any answer you get here will be given from a C POV, and might therefore not apply to C++. Richard |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Jan 28, 2:08 am, DDD <1983...@gmail.com> wrote:
> I have some codes: > w_char **sFieldsUri; > sFieldsUri = &(new w_char[2]); new w_char[2] will return a w_char*, so far so good. Except you are trying to take the address of non lvalue ... Enable ALL warning/error messages from your compiler, you should get an error. &(new w_char[2]) is really weird, really (besides from taking the adress of non lvalue) it is like wrting int* p = &3; > > w_char **sValFind = nsnull; > sValFind = &(new w_char[2]); > > When I debug my program, I found the above code had some strange > things. sFieldsUri+1 is equal to sValFind+0. I am still surprised that your compiler can compile this. > > But if I change the codes to the following: > w_char **sFieldsUri; > sFieldsUri = &(new w_char[2]); forget it. > > for(int i=0; i<2; i++) > { > sFieldsUri[i] = new w_char[100]; > } > > w_char **sValFind = nsnull; > sValFind = &(new w_char[2]); > > for(int i=0; i<2; i++) > { > sVal Find[i] = new w_char[100]; > } > sFieldsUri+0, sFieldsUri+1, and sValFind+0, sValFind+1 are all > difference. > Thanks for all. If I were a gambler I would say you want that: w_char **sFieldsUri; sFieldsUri = new w_char*[2]; // notice the '*' thing and try to re-run/compile your program. you should get a decent compiler dude. Cheers, Paulo |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
ppi wrote:
> On Jan 28, 2:08 am, DDD <1983...@gmail.com> wrote: >> I have some codes: >> w_char **sFieldsUri; >> sFieldsUri = &(new w_char[2]); > > new w_char[2] will return a w_char*, Not it C, it won't. It's a syntax error. so far so good. Bullshit. |
|
![]() |
| Outils de la discussion | |
|
|