pointer-to-two-adjactend-chars

R

.rhavin grobert

this is m$ vc++, but the question itself is c++ specific...

TCHAR is a 'char' in non-unicode.

functions return...
TCHAR* CString::GetBuffer(int);
int CString::GetLenght(int);
__________________________________________

// code:

CString str ="SomeStringWithMoreThanOneTChar";
TCHAR *(pEnd[2]) = /* § */ str.GetBuffer(str.GetLength()) +
str.GetLength() - 2;
// in other words: a pointer to the second-last TCHAR is returned
__________________________________________

in the place marked "/* § */", a cast is neccesary. My problem: i dont
find the correct syntax.
the error given is "cannot convert from 'char *' to 'char *[2]' ", but
inserting

(char *[2]), (char (*[2])), ((char*) [2]) or (*(char[2])) doesnt work.
Anyone knows the correct syntax for a cast to a pointer-to-two-
adjactend-TCHARs please?
 
P

peter koch

this is m$ vc++, but the question itself is c++ specific...

TCHAR is a 'char' in non-unicode.

functions return...
TCHAR* CString::GetBuffer(int);
int CString::GetLenght(int);
__________________________________________

// code:

CString str ="SomeStringWithMoreThanOneTChar";
TCHAR *(pEnd[2]) = /* § */ str.GetBuffer(str.GetLength()) +
str.GetLength() - 2;
// in other words: a pointer to the second-last TCHAR is returned

It does not look like that to me. I do not know CString, but this
looks like a runaway buffer.
__________________________________________

in the place marked "/* § */", a cast is neccesary. My problem: i dont
find the correct syntax.
the error given is "cannot convert from 'char *' to 'char *[2]' ", but
inserting

(char *[2]), (char (*[2])), ((char*) [2]) or (*(char[2])) doesnt work.
Anyone knows the correct syntax for a cast to a pointer-to-two-
adjactend-TCHARs please?

You can't without a cast, but does it matter? If you used a char* (I
am surprised you don't use a char const*), char[0] points to the
second last character and char[1] to the last (assuming that your code
is correct, of course).

/Peter
 
G

gw7rib

this is m$ vc++, but the question itself is c++ specific...

TCHAR is a 'char' in non-unicode.

functions return...
TCHAR* CString::GetBuffer(int);
int CString::GetLenght(int);
__________________________________________

// code:

CString str ="SomeStringWithMoreThanOneTChar";
TCHAR *(pEnd[2]) = /* § */ str.GetBuffer(str.GetLength()) +
str.GetLength() - 2;
// in other words: a pointer to the second-last TCHAR is returned
__________________________________________

in the place marked "/* § */", a cast is neccesary. My problem: i dont
find the correct syntax.
the error given is "cannot convert from 'char *' to 'char *[2]' ", but
inserting

(char *[2]), (char (*[2])), ((char*) [2]) or (*(char[2])) doesnt work.
Anyone knows the correct syntax for a cast to a pointer-to-two-
adjactend-TCHARs please?

Is there some reason why you need a pointer to two TCHARs? Can't you
make do with a pointer to the first one, and look at the next location
to find the second one when you need it?

I mean in a similar way to the the way strings are handled in C. You
don't actually have a pointer to the "whole string", you (normally)
have just a pointer to the first character of it. But from this
pointer you can find the second, third etc characters when you need
them.

Incidentally, your code looks odd, using chars in some places and
TCHARs in others. I'm not sure what use this is. If the code is being
written purely for non-Unicode, then there seems no reason to use
TCHARs at all. Whereas, if the code might one day be used with
Unicode, you would find it convenient to have it all set up that way -
which would require adding "_TEXT"s and the like to your code.

Hope that helps.
Paul.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top