PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > memory address of *char
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
memory address of *char

Réponse
 
LinkBack Outils de la discussion
Vieux 28/01/2008, 07h08   #1
DDD
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut memory address of *char

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.
  Réponse avec citation
Vieux 28/01/2008, 07h20   #2
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: memory address of *char

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
  Réponse avec citation
Vieux 28/01/2008, 07h38   #3
Martin Ambuhl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: memory address of *char

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.
  Réponse avec citation
Vieux 28/01/2008, 08h59   #4
Richard Bos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: memory address of *char

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
  Réponse avec citation
Vieux 28/01/2008, 15h48   #5
ppi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: memory address of *char

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


  Réponse avec citation
Vieux 28/01/2008, 20h57   #6
Martin Ambuhl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: memory address of *char

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13031 seconds with 14 queries