473,800 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with a pointer

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

Dec 23 '05
14 4417
thank you for all, with yours answers the problem is solved!
I think I need to understand why... but is solved.

Happy Xmas for all
Maurizio

Dec 23 '05 #11
Anand wrote:
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*)


I missed that, sorry. In that, if you really do mean to access that
address, and the system you are using will allow you to do that, then
you need a cast because integer types and pointer types are completely
different things (0 is a special case as it is a null pointer constant).
So for a "void *ptr" , doing "*ptr" is invalid.
But for "void **ptr", doing "*ptr" is fully valid.

Or did I miss something?


You are correct about that, I missed the second *.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 23 '05 #12
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.c om, 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.annou nce.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

Dec 23 '05 #13

Anand wrote:

[snip]
And hence the warnings from the compiler


some thing like this removes the warning

*pMDMA_S0_START _ADDR = (void *)0x04000;

Dec 23 '05 #14
In article <11************ **********@g43g 2000cwa.googleg roups.com>,
mauri1106 <mi****@tin.i t> wrote:
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
As others noted, D0 (dee-zero) vs S0 (ess-zero) makes a big
difference.

That aside, there are a couple of peculiar things going on here.

First, "volatile" suggests you are attempting to program hardware.
This is inherently non-portable. (You can add an abstraction layer,
to make the C code port to "those systems on which the hardare can
be found", and this is often a good idea, but the job itself remains
non-portable so one may as well discard attempts to use nothing
but Standard C. The question then becomes what to put in the
abstraction layer.)

Second, the name MDMA suggests this has something to do with direct
memory access hardware, e.g., I/O devices. (I assume it is not
methylene-dioxy-methamphetamine , aka Ecstasy. :-) ) These tend to
talk to hardware-oriented RAM addresses, rather than C-oriented
software memory addresses. On many machines, the hardware addresses
are different from the software addresses, making C's "void *"
(generic data pointer) type a poor choice for a "hardware DMA
abstraction layer". You probably want some other (likely integral)
type that you can pass around as a "physical address".

This is one of the rare cases where a typedef is useful, e.g.,
using the POSIX namespace:

/* 64-bit physical address, using this compiler's 64-bit integers */
typedef unsigned long long dmaaddr_t;

Or:

/* 32-bit physical address, using this compilers 32-bit integers */
typedef unsigned int dmaaddr_t;

Of course, if "void *" really is suitable for physical DMA
addresses (which also means "you do not need to do arithmetic
on them", which is rare), you could:

typedef void *dmaaddr_t;

In any case, once you have chosen an appropriate "DMA address type",
you can then define a (highly-machine-specific) macro like
pMDMA_S0_START_ ADDR using that type:

#define pMDMA_D0_START_ ADDR (*(volatile dmaaddr_t *)0x12345678)

(although I find that putting these things into data structures
is often wise.)
... 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;


This is because the thing on the right is an "int" (0x04000 or
16384), while the thing on the left is a "void *".

If you were using a type-alias (typedef) to hide the actual hardware
data type, you might write:

*pMDMA_S0_START _ADDR = (dmaaddr_t)0x40 00;

although this obviously assumes that "0x4000" is the correct way
to express the address as an integer (for that particular machine).
If it is in fact the correct way, it seems likely that "dmaaddr_t"
should be integral in the first place.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Dec 23 '05 #15

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

Similar topics

4
2143
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived classes
28
2133
by: Davy | last post by:
Hi all, I found char x={"my"}; can be compiled. But char x; x={"my"}; can not be compiled.
5
6064
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user hits the right and left keys to move this insertion point (cursor) Here is the problem:
37
2326
by: Patrik Huber | last post by:
Hello! I got the following Code in Assembler (NASM), which prints out "5" in realmode: mov ax, 0xB800 mov es, ax mov byte , '5' I want to do the same in gcc now, but I'm stuck. GCC doesn't like the
8
10720
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to receive a byte array as one of its parameters. The project is marked for COM interop, and that all proceeds normally. When I reference the type library in the VB6 project, and write the code to call the function that returns the byte array, it works
0
3945
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
2
4456
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c */ #include <time.h>
7
2047
by: Marcelo | last post by:
Hi everybody, I don't understand why I am having a problem in this code. The problem is that my pointer *phist in main method, it is declared. Then I send the pointer to my method, and this method creates a new object (a Matrix) for it. I suppose that after the new operator, my pointer is pointing to an object, so when the method has finished, the very first pointer is still poitint to the created method; however this is not working,...
39
19654
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
3
2638
by: iskeletor | last post by:
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define STUDENT_NUMBER 68 #define ARRAY_LENGTH 10 struct node{ char Name,Surname; int data,no;
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.