Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Problem with a pointer

Reply
Thread Tools

Problem with a pointer

 
 
mauri1106
Guest
Posts: n/a
 
      12-23-2005
Hi, I have a little problem with a pointer.

In my project is included an ".h" file with this declaration:

"#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"

If I assign a value (e.g. *pMDMA_S0_START_ADDR = 0x04000 the
compiler give me these 2 warning:


".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
be
assigned to an entity of type "void *"
*pMDMA_S0_START_ADDR = 0x04000;
^

".\init.c", line 105: cc0152: {D} warning: conversion of nonzero
integer to
pointer
*pMDMA_S0_START_ADDR = 0x04000;
^

Why appears these warnings?

thanks, Maurizio

 
Reply With Quote
 
 
 
 
Ravi Uday
Guest
Posts: n/a
 
      12-23-2005


mauri1106 wrote:
> Hi, I have a little problem with a pointer.
>
> In my project is included an ".h" file with this declaration:
>
> "#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"
>
> If I assign a value (e.g. *pMDMA_S0_START_ADDR = 0x04000 the


How is pMDMA_S0_START_ADDR defined ?

> compiler give me these 2 warning:
>
>
> ".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
> be
> assigned to an entity of type "void *"
> *pMDMA_S0_START_ADDR = 0x04000;
>

^
Thats probably because your #define is pMDMA_D0_START_ADDR
^^
and error you got points to *pMDMA_S0_START_ADDR
^^

Post the real code please !
One more suggestion is you could look at the pre-processor output
to see how your macro has expanded in the code.

- Ravi

>
> ".\init.c", line 105: cc0152: {D} warning: conversion of nonzero
> integer to
> pointer
> *pMDMA_S0_START_ADDR = 0x04000;
> ^
>
> Why appears these warnings?
>
> thanks, Maurizio
>


 
Reply With Quote
 
 
 
 
mauri1106
Guest
Posts: n/a
 
      12-23-2005
I'm sorry, is correct with "S0" in assegnation!

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      12-23-2005
mauri1106 wrote:
> Hi, I have a little problem with a pointer.
>
> In my project is included an ".h" file with this declaration:
>
> "#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"


I assume that you also have something like the following in our header:
#define MDMA_DO_START_ADDR 0x12345678

In future, please provide a *complete* minimal example that shows the
problem (compilable, unless the problem is that it won't compiler).

> If I assign a value (e.g. *pMDMA_S0_START_ADDR = 0x04000 the
> compiler give me these 2 warning:
>
>
> ".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
> be
> assigned to an entity of type "void *"
> *pMDMA_S0_START_ADDR = 0x04000;


That's simple. void* is a generic pointer type, so of course you can't
read or write through a void* pointer. You need to have a pointer to a
complete, known type, e.g. int or char.

> ".\init.c", line 105: cc0152: {D} warning: conversion of nonzero
> integer to
> pointer


That's simple as well. The only integer to pointer fully defined by the
C standard is that 0 converts to a null pointer. For the rest, it is
implementation defined with one possible definition being that there is
no integer type large enough to represent pointers.

> *pMDMA_S0_START_ADDR = 0x04000;
> ^
>
> Why appears these warnings?


Because you are writing terrible code. I'm guessing that you are trying
to access hardware directly, but depending on the OS you are using (if
you are using one) this may not be possible, but even if it is the
compiler needs to know the type of what it is trying to access.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
 
Reply With Quote
 
mauri1106
Guest
Posts: n/a
 
      12-23-2005
the correct assegantion is:

"#define pMDMA_S0_START_ADDR ((void * volatile *)MDMA_S0_START_ADDR)"

The code is very simple and in prctice is only this declaration, the
others parts work correctly.

Thanks

 
Reply With Quote
 
Anand
Guest
Posts: n/a
 
      12-23-2005
mauri1106 wrote:
> Hi, I have a little problem with a pointer.
>
> In my project is included an ".h" file with this declaration:
>
> "#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"
>
> If I assign a value (e.g. *pMDMA_S0_START_ADDR = 0x04000 the
> compiler give me these 2 warning:
>
> ".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
> be assigned to an entity of type "void *"
> *pMDMA_S0_START_ADDR = 0x04000;
> ^
> ".\init.c", line 105: cc0152: {D} warning: conversion of nonzero
> integer to pointer
> *pMDMA_S0_START_ADDR = 0x04000;
> ^
> Why appears these warnings?
>
> thanks, Maurizio
>

Searching the archives of the group would give the complete discussion
about this section.

Here's a snippet from standard:
"An integer may be converted to any pointer type. Except as previously
specified, the result is implementation-defined, might not be correctly
aligned, might not point to an entity of the referenced type, and might
be a trap representation."

And hence the warnings from the compiler
--
(Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
(clc FAQ) http://www.eskimo.com/~scs/C-faq/top.html
 
Reply With Quote
 
mauri1106
Guest
Posts: n/a
 
      12-23-2005
Dear anand, can you better explain your answer? I don't understand what
do you want to say.
thanks

 
Reply With Quote
 
Chuck F.
Guest
Posts: n/a
 
      12-23-2005
mauri1106 wrote:
>
> Dear anand, can you better explain your answer? I don't
> understand what do you want to say. thanks


I suggest you do some reading about how to post etc. on usenet.
Here is some info, and there are more links in my sig. below.

"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
Anand
Guest
Posts: n/a
 
      12-23-2005
<quote-correction>
mauri1106: Please ensure to quote the previous reply. This gives a
context to the mail. I've corrected this time.
</quote-correction>
> Anand Wrote:
>
>Here's a snippet from standard:
>"An integer may be converted to any pointer type. Except as previously
>specified, the result is implementation-defined, might not be

correctly >aligned, might not point to an entity of the referenced type,
and might >be a trap representation."
>
>mauri1106 wrote:
>> Dear anand, can you better explain your answer? I don't understand what
>> do you want to say.
>> thanks
>>

I assume you didn't search the archives of this group.

What you have is a void**ptr. So the moment you redirect it you have is
a void* (a pointer) and you are assigning an integer value to it.
And hence the warnings.

"ptr <- integer" is an implementation defined behavior and it's not
guaranteed to work.

Anyway, only valid and portable integer value that can be assigned to
any pointer is 0. (Which is NULL pointer).
If you are trying to assign any other integer to the pointer it purely
depends on your compiler and platform as to how to treat it.

The hard coded integer value you are assigning is purely dependent on
your environment in which the code is going to run.
For all you know you memory location 0x04000 could be invalid (you might
not have access to it).
Or there's no way to represent a memory location using just integers in
your system.

There are times when this may be valid (and in those cases you are very
much aware of it.) But then it's still the duty of your compiler to warn
you.

Now you decide, do you always have access to 0x4000 memory location (if
that's how you refer a location in your system) is valid and you have
full rights and doesn't cause any problem in that particular system.

--
(Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
(clc FAQ) http://www.eskimo.com/~scs/C-faq/top.html
 
Reply With Quote
 
Anand
Guest
Posts: n/a
 
      12-23-2005
Flash Gordon wrote:
> mauri1106 wrote:

[...]
>> "#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"

[...]
>>
>>
>> ".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
>> be
>> assigned to an entity of type "void *"
>> *pMDMA_S0_START_ADDR = 0x04000;

>
>
> That's simple. void* is a generic pointer type, so of course you can't
> read or write through a void* pointer. You need to have a pointer to a
> complete, known type, e.g. int or char.

[...]
That's void** (or at least that's what it's type casted to). So in that
case doesn't it qualify to be a complete type? (of void*)

So for a "void *ptr" , doing "*ptr" is invalid.
But for "void **ptr", doing "*ptr" is fully valid.

Or did I miss something?
--
(Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
(clc FAQ) http://www.eskimo.com/~scs/C-faq/top.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to an array vs pointer to pointer subramanian100in@yahoo.com, India C Programming 5 09-23-2011 10:28 AM
Pointer to pointer or reference to pointer A C++ 7 07-05-2011 07:49 PM
Pointer to pointer Vs References to Pointer bansalvikrant@gmail.com C++ 4 07-02-2009 10:20 AM
passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer jimjim C Programming 16 03-27-2006 11:03 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM



Advertisments