473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

memory address of *char

DDD
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.
Jan 28 '08 #1
4 1805
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
Jan 28 '08 #2
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.
Jan 28 '08 #3
DDD <19*****@gmail.comwrote:
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
Jan 28 '08 #4
ppi
On Jan 28, 2:08 am, DDD <1983...@gmail.comwrote:
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
Jan 28 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: lupher cypher | last post by:
Hi, I'm trying to access memory directly at 0xb800 (text screen). I tried this: char far* screen = (char far*)0xb8000000; but apparently c++ compiler doesn't know "far" (says "syntax error...
1
by: Riadh Elloumi | last post by:
Hi, I have some problems when debugging memory allocation (for both malloc and new) in a program that uses standard lists and vectors. When I add an element to the vector, the overloaded...
32
by: John | last post by:
Hi all: When I run my code, I find that the memory that the code uses keeps increasing. I have a PC with 2G RAM running Debian linux. The code consumes 1.5G memory by the time it finishes...
12
by: jois.de.vivre | last post by:
Hi, I have the following piece of code that is designed to help me add debug traces to my program (I wanted to use purely C++ code, but the only way I know how to do something like this is with...
18
by: Abhishek | last post by:
lets consider that I have defined an integer like this. int a=5; now taking the fact that an integer is allocated 2 bytes in memory and the memory address increases in the left to right direction,...
4
by: voidtwerp | last post by:
Hi, I hope this is not too OT but I would like clarification on how classes are held in memory. each object obviously has an individual copy of its data. I guess a class would only have one...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
15
by: sethukr | last post by:
Hi everybody, While running the following program in GCC, i'm very much screwed. main() { char *ptr1; char arr; int i; char *ptr2;
1
by: krishna81m | last post by:
In the following code, I am trying to return a char, a char* (a type of non-const without using new, what do we call this type of pointer?) and char* created using new operator. What I do not know at...
0
by: Hypnotik | last post by:
My program is to simulate cache memory. I read in the info from 2 external files, 1) access 2) data in memory. When I read the information in I display the info...and it is all correct. However...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.