473,387 Members | 1,388 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,387 software developers and data experts.

memory address of *wchar_t

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
2 2934
DDD wrote:
I have some codes:
w_char **sFieldsUri;
Okay, sFieldsUri is a pointer to a pointer to a w_char.
sFieldsUri = &(new w_char[2]);
new returns a pointer to the allocated memory. You are trying to get the
address of this pointer? wtf? I don't think this is what you really want
to do.

Now, if you wanted your sFieldsUri to pointer two two arrays of w_char,
first you need to allocate memory for the pointers themselves.

sFieldsUri = new w_char*[2];
Now sFieldsUri would point to to w_char pointers. Now you could allocate
the acutal memory for the w_chars.

sFieldsUri[0] = new w_char[somesize];
sFieldsUri[1] = new w_char[somesize];

Allocating memory this way is fairly confusing and one can get lost as to
where their pointers actually point. It is better to not use pointers if
you can. What is wrong with std::string?
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.


--
Jim Langston
ta*******@rocketmail.com
Jan 28 '08 #2
DDD
On Jan 29, 12:10*am, "Jim Langston" <tazmas...@rocketmail.comwrote:
DDD wrote:
I have some codes:
* * * *w_char **sFieldsUri;

Okay, sFieldsUri is a pointer to a pointer to a w_char.
* * * *sFieldsUri = &(new w_char[2]);

new returns a pointer to the allocated memory. *You are trying to get the
address of this pointer? *wtf? *I don't think this is what you really want
to do.

Now, if you wanted your sFieldsUri to pointer two two arrays of w_char,
first you need to allocate memory for the pointers themselves.

sFieldsUri = new w_char*[2];
Now sFieldsUri would point to to w_char pointers. *Now you could allocate
the acutal memory for the w_chars.

sFieldsUri[0] = new w_char[somesize];
sFieldsUri[1] = new w_char[somesize];

Allocating memory this way is fairly confusing and one can get lost as to
where their pointers actually point. *It is better to not use pointers if
you can. *What is wrong with std::string?
* * * *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.

--
Jim Langston
tazmas...@rocketmail.com
Thank you very much, Jim. Yes, you are right. &(new w_char[2]) is not
I wanna get. And new w_char*[2] works well.
Last, I wanna say that &(new w_char[2]) works differently in debug and
release version, because sValFind = &(new w_char[2]) is a error, a
big error.

Jan 30 '08 #3

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

Similar topics

3
by: Julius Mong | last post by:
Hi all, I'm doing this: // Test char code wchar_t lookup = {0x8364, 0x5543, 0x3432, 0xabcd, 0xef01}; for (int x=0; x<5; x++) { wchar_t * string = (wchar_t*) malloc(sizeof(wchar_t)); string =...
7
by: boss_bhat | last post by:
Hi all , I am beginner to C programming. I have a defined astructure like the following, and i am using aliases for the different data types in the structure, typedef struct _NAME_INFO {...
1
by: Mark Fancy | last post by:
I have a project that I'm trying to get to compile. I need to have the /Tc:wchar_t compile switch in order to use some libraries. I have included the following header files: #include <mapix.h>...
1
by: jjf | last post by:
Do Standard C's wide characters and wide strings require absolutely that each character be stored in a single wchar_t, or can characters be "multi-wchar_t" in the same way that they can be...
12
by: Jens Theisen | last post by:
Hello, does anyone know which layer is responsible for defining the size of wchar_t? Naturally enough, it's not defined in the language. I looked in the SystemV processor supplement and the...
8
by: Rui Maciel | last post by:
I've just started learning how to use the wchar_t data type as the basis for Unicode strings and unfortunately I'm having quite a bit of problems, both in the C front and the Unicode front. In...
3
by: john | last post by:
As far as I know there is only the type wchar_t. However my compiler compiles both "signed wchar_t" and "unsigned wchar_t". Are there both signed and unsigned wchar_t types?
16
by: Michael Brennan | last post by:
I guess this question only applies to programming applications for UNIX, Windows and similiar. If one develops something for an embedded system I can understand that wchar_t would be unnecessary. ...
5
by: yakir22 | last post by:
Hello experts, I am dealing now in porting our server from windows to linux. our client is running only on windows machine. to avoid the wchar_t size problem ( in windows its 2 bytes and linux is...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.