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

Using Double pointer

Why the following happening?

UINT m_uArrXpos[4][7];

UINT **p = m_uArrXposSchema; // Failed to compile

UINT **p = (UINT**)m_uArrXposSchema; // Success compilation

May 29 '07 #1
9 2620
Sarath wrote:
Why the following happening?

UINT m_uArrXpos[4][7];

UINT **p = m_uArrXposSchema; // Failed to compile
What ever "m_uArrXposSchema" is, it isn't a "UINT**" (whatever "UINT" is).
UINT **p = (UINT**)m_uArrXposSchema; // Success compilation
You lied to the compiler.

--
Ian Collins.
May 29 '07 #2
On May 29, 5:27 pm, Ian Collins <ian-n...@hotmail.comwrote:
Sarath wrote:
Why the following happening?
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXposSchema; // Failed to compile

What ever "m_uArrXposSchema" is, it isn't a "UINT**" (whatever "UINT" is).
UINT **p = (UINT**)m_uArrXposSchema; // Success compilation

You lied to the compiler.

--
Ian Collins.
Thanks Collins for your reply.

BTW UINT defined as

typedef unsigned int UINT;

What i've lied to compiler? It's a two dimensional array no?

Could you please be more specific?

May 29 '07 #3
On May 29, 5:27 pm, Ian Collins <ian-n...@hotmail.comwrote:
Sarath wrote:
Why the following happening?
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXposSchema; // Failed to compile

What ever "m_uArrXposSchema" is, it isn't a "UINT**" (whatever "UINT" is).
UINT **p = (UINT**)m_uArrXposSchema; // Success compilation

You lied to the compiler.

--
Ian Collins.
Another funniest thing is that,

UINT m_uArrXpos[4][7];
UINT **p = m_uArrXpos; // Failed to compile
UINT **p = (UINT**)m_uArrXpos; // Success compilation
UINT **p = static_cast<UINT**>(m_uArrXpos); // Failed to compile

What it makes in difference static_cast and C style cast?

I'm using Visual C++ 6.0 Compiler

May 29 '07 #4
Sarath <CS*****@gmail.comwrites:
>What i've lied to compiler? It's a two dimensional array no?
>Could you please be more specific?
http://burks.bton.ac.uk/burks/langua...trtut/ch7x.htm
might help (and in general this kind of problem is more often dealt with in C books/boards than in C++ ones). Two dimensional arrays aren't all the same.
May 29 '07 #5
Sarath wrote :
On May 29, 5:27 pm, Ian Collins <ian-n...@hotmail.comwrote:
>Sarath wrote:
>>Why the following happening?
>>UINT m_uArrXpos[4][7];
>>UINT **p = m_uArrXposSchema; // Failed to compile

What ever "m_uArrXposSchema" is, it isn't a "UINT**" (whatever "UINT" is).
>>UINT **p = (UINT**)m_uArrXposSchema; // Success compilation

You lied to the compiler.

--
Ian Collins.

Another funniest thing is that,

UINT m_uArrXpos[4][7];
UINT **p = m_uArrXpos; // Failed to compile
UINT **p = (UINT**)m_uArrXpos; // Success compilation
UINT **p = static_cast<UINT**>(m_uArrXpos); // Failed to compile

What it makes in difference static_cast and C style cast?

I'm using Visual C++ 6.0 Compiler
The difference is that static_cast is safe, while a C style cast can
also be a reinterpret_cast (and possibly a const_cast).

UINT* is a pointer that points to UINT. We could do
typedef UINT* UINTPTR;
to create a typedef for such a pointer.

Now, what is UINTPTR*? A pointer that points to UINTPTR. And since
UINTPTR is itself a pointer to UINT, that makes UINTPTR* the same as
UINT**, or a pointer that points to [a pointer that points to UINT].
You can use it as a two-dimensional array, but then it's representation
would be an array of pointers that point to arrays of UINTs. E.g., p[0]
is a pointer of type UINT* that points to an array of UINTs, p[1] is
also a pointer, etc.

m_uArrXpos is an array of 4x7 UINTs. It's not an array of pointers that
point to UINT. Therefore you cannot assign a UINT[4][7] to a UINT*. You
can convert it to a (UINT*)[7] though (which is a pointer that points
to an array of 7 UINTs)

- Sylvester
May 29 '07 #6
On May 29, 5:40 pm, Sarath <CSar...@gmail.comwrote:
On May 29, 5:27 pm, Ian Collins <ian-n...@hotmail.comwrote:
Sarath wrote:
Why the following happening?
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXposSchema; // Failed to compile
What ever "m_uArrXposSchema" is, it isn't a "UINT**" (whatever "UINT" is).
UINT **p = (UINT**)m_uArrXposSchema; // Success compilation
You lied to the compiler.
--
Ian Collins.

Another funniest thing is that,

UINT m_uArrXpos[4][7];
UINT **p = m_uArrXpos; // Failed to compile
UINT **p = (UINT**)m_uArrXpos; // Success compilation
UINT **p = static_cast<UINT**>(m_uArrXpos); // Failed to compile

What it makes in difference static_cast and C style cast?

I'm using Visual C++ 6.0 Compiler
Dear Sarath,

You are using a two dimensional array and not a pointer array. A
two dimensional array dont have a "**". Suppose the location given in
m_uArrXpos is 0x0012fef4. the value at this location will not be an
address. Insted it will be a value of the m_uArrXpos[0][0], So
defenitly a pointer is made to an invalid location. Even though the C
style cast works it will be a junk pointer. You cant use it out.
Compiler prevents this casting untill and otherwise you force to do
the casting.

Thanks,
Amal P.

May 29 '07 #7
On May 29, 6:39 pm, Amal P <enjoyam...@gmail.comwrote:
On May 29, 5:40 pm, Sarath <CSar...@gmail.comwrote:


On May 29, 5:27 pm, Ian Collins <ian-n...@hotmail.comwrote:
Sarath wrote:
Why the following happening?
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXposSchema; // Failed to compile
What ever "m_uArrXposSchema" is, it isn't a "UINT**" (whatever "UINT" is).
UINT **p = (UINT**)m_uArrXposSchema; // Success compilation
You lied to the compiler.
--
Ian Collins.
Another funniest thing is that,
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXpos; // Failed to compile
UINT **p = (UINT**)m_uArrXpos; // Success compilation
UINT **p = static_cast<UINT**>(m_uArrXpos); // Failed to compile
What it makes in difference static_cast and C style cast?
I'm using Visual C++ 6.0 Compiler

Dear Sarath,

You are using a two dimensional array and not a pointer array. A
two dimensional array dont have a "**". Suppose the location given in
m_uArrXpos is 0x0012fef4. the value at this location will not be an
address. Insted it will be a value of the m_uArrXpos[0][0], So
defenitly a pointer is made to an invalid location. Even though the C
style cast works it will be a junk pointer. You cant use it out.
Compiler prevents this casting untill and otherwise you force to do
the casting.

Thanks,
Amal P.- Hide quoted text -

- Show quoted text -
Hmmm... Seems like to learn everything from start :D

May 29 '07 #8
On May 29, 6:04 am, Sarath <CSar...@gmail.comwrote:
On May 29, 6:39 pm, Amal P <enjoyam...@gmail.comwrote:
On May 29, 5:40 pm, Sarath <CSar...@gmail.comwrote:
On May 29, 5:27 pm, Ian Collins <ian-n...@hotmail.comwrote:
Sarath wrote:
Why the following happening?
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXposSchema; // Failed to compile
What ever "m_uArrXposSchema" is, it isn't a "UINT**" (whatever "UINT" is).
UINT **p = (UINT**)m_uArrXposSchema; // Success compilation
You lied to the compiler.
--
Ian Collins.
Another funniest thing is that,
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXpos; // Failed to compile
UINT **p = (UINT**)m_uArrXpos; // Success compilation
UINT **p = static_cast<UINT**>(m_uArrXpos); // Failed to compile
What it makes in difference static_cast and C style cast?
I'm using Visual C++ 6.0 Compiler
Dear Sarath,
You are using a two dimensional array and not a pointer array. A
two dimensional array dont have a "**". Suppose the location given in
m_uArrXpos is 0x0012fef4. the value at this location will not be an
address. Insted it will be a value of the m_uArrXpos[0][0], So
defenitly a pointer is made to an invalid location. Even though the C
style cast works it will be a junk pointer. You cant use it out.
Compiler prevents this casting untill and otherwise you force to do
the casting.
Thanks,
Amal P.- Hide quoted text -
- Show quoted text -

Hmmm... Seems like to learn everything from start :D
You mean unlearn. You are being confused because of too much code
hiding the details about the type involved. If you declare a 2D array
of unsigned integers, the elements are unsigned integers, not
pointers.

It is recommended not to hide pointers behind decorations. You'll find
some platforms that use these decorations to isolate your code from
any future changes they make as well as hide their implementations.
That doesn't mean you should be hiding your code from yourself.

#include <iostream>

typedef unsigned UINT; // no problem
typedef UINT* PTR; // this is ugly
typedef UINT** PTRPTR; // this is mischievious

int main()
{
// a container of primitives
UINT Arr[2][2];
Arr[0][0] = 99;
Arr[1][1] = 88;

unsigned* p = &Arr[0][0];
std::cout << *p << std::endl; // 99
p = &Arr[1][1];
std::cout << *p << std::endl; // 88

// a container of pointers
PTR Pointers[2][2]; // all point to nothing
Pointers[0][0] = &Arr[0][0]; // ok
unsigned* pu = Pointers[0][0];
std::cout << *pu << std::endl; // 99

// a container of pointers to pointers
PTRPTR PtrPtr[2][2]; // all point to invalid pointers
PtrPtr[0][0] = &Pointers[0][0]; // ok, ptr set to a valid ptr
unsigned** ppu = PtrPtr[0][0];
std::cout << **ppu << std::endl; // 99
}

May 29 '07 #9
Sarath <CS*****@gmail.comwrote in news:1180427071.782839.307170
@n15g2000prd.googlegroups.com:
Why the following happening?

UINT m_uArrXpos[4][7];

UINT **p = m_uArrXposSchema; // Failed to compile
Because m_uArrXposSchema "decays" into a simple UINT*. You can't simply
assign a UINT* to a UINT**.
UINT **p = (UINT**)m_uArrXposSchema; // Success compilation
You forcibly casted the pointer into a UINT**. You told the compiler to
"shut-up, I know what I'm doing".
May 29 '07 #10

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

Similar topics

6
by: S Manohar | last post by:
I need to pass a 'reference' to a double value to a function which changes that value. Each time the function is called, it needs to change different sets of values. In C I'd simply pass...
2
by: Tony Johansson | last post by:
Hello Experts! I have one class template here called Handle and one concrete class called Point. At the bottom is the main program and the class template definitions for Handle. This program...
10
by: Robert Palma | last post by:
I'm having trouble figuring out how to pass a pointer to a double array (1 dimensional) to a C function. Declaring array as: double xx; Declaring func. int process( double *input ) Calling...
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
14
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are...
42
by: xdevel | last post by:
Hi, if I have: int a=100, b = 200, c = 300; int *a = {&a, &b, &c}; than say that: int **b is equal to int *a is correct????
6
by: semkaa | last post by:
Can you explain why using ref keyword for passing parameters works slower that passing parameters by values itself. I wrote 2 examples to test it: //using ref static void Main(string args) {...
10
by: kkirtac | last post by:
Hi, i have a void pointer and i cast it to an appropriate known type before using. The types which i cast this void* to are, from the Intel's open source computer vision library. Here is my piece...
6
by: rainy6144 | last post by:
Does the following code have defined behavior? double *new_array(unsigned n) { double *p = malloc(n * sizeof(double)); unsigned i; for (i = 0; i < n; i++) p = 0.0; return p; }
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.