C programming on ARM

Hi all,

How can I correct the following error on ARM7 with C programming?

'=': implicit cast of pointrt to non-equal pointer

thx and regards

Reply to
aamer
Loading thread data ...

Use two pointers of the same type.

Reply to
Arlet Ottens

Or cast to the correct type (if you are sure and know what you're doing).

--
Posted via a free Usenet account from http://www.teranews.com
Reply to
Jim Relsh

If he knew what he was doing, he wouldn't have posted that question. ;)

--
Grant Edwards                   grante             Yow! Is this an out-take
                                  at               from the "BRADY BUNCH"?
                               visi.com
Reply to
Grant Edwards

Caution. Most pointer casts are implementation defined. The exception is casting to and from void*, and from void* back to the original type.

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.
Reply to
CBFalconer

Try proper casting.

Karthik Balaguru

Reply to
karthikbalaguru

In which case would an arbitrary pointer casting be a problem ?

The only situation I can think of is for instance some DSP with 24 bit addressable unit or some old 36 bit mainframe, in which for instance a char* would require the memory word and also information which quarter word is referenced.

With any byte addressable architecture, a pointer is just a pointer.

Paul

Reply to
Paul Keinanen

Roughly all of them. The real question is how violently the problem will show itself. Some of them can lie dormant for a decade before a platform change exposes them as total show-stoppers.

But there are quite a few non-byte addressable architectures out there. Including ARM, last I checked.

Reply to
Hans-Bernhard Bröker

Actually, ARM cores are capable of byte addressing (at least any of the currently supported architectures).

Some ARM devices may have restrictions on certain types of memory, though.

Reply to
Arlet

itself. Some of them can lie dormant

Actually most architectures are byte addressable, including ARM, so casting pointers just works. Of course it's essential to know what you're doing - well written programs rarely need pointer casts.

Wilco

Reply to
Wilco Dijkstra

True, but many of them (ARM, SPARC, MSP430, ...) have alignment requirements for objects larger than 1 byte in size.

Unless the resulting pointer is misaligned.

--
Grant Edwards                   grante             Yow! It was a JOKE!!
                                  at               Get it??  I was receiving
                               visi.com            messages from DAVID
                                                   LETTERMAN!!  !
Reply to
Grant Edwards

Depends on what exactly you mean by the term.

AFAIK ARM7 is byte-addressable only for bytes, but not for larger objects. Well, may be it's just me, but I wouldn't call what happens when an ARM7 accesses a 32-bit integer without 4-byte alignment "addressing".

Reply to
Hans-Bernhard Bröker

Well, may be it's just me, but I wouldn't

alignment "addressing".

Obviously not all possible pointer values are valid for all types. This doesn't affect byte addressability as casting between char* and int* doesn't lose information. Accessing a misaligned pointer will result in an exception (which is a good way to detect corrupted pointers). However if you use the correct type (eg. __packed int *p rather than int *p), the compiler will generate an unaligned access.

Similarly a 32-bit CPU with less than 4GB of memory doesn't have (say) a 18.25-bit address space - it still has a 32-bit address space of which only a small proportion is valid.

Wilco

Reply to
Wilco Dijkstra

Byte addressability refers to the smallest unit of addressability, not to the coursest.

Or the pointer is aligned but points to the wrong place, or invalid memory, or a peripheral, or ... If you don't know what you're doing then pointer casting is likely the least of your problems.

My point was that the bitpatterns of all pointer types are the same for all addresses in the address space.

Wilco

Reply to
Wilco Dijkstra

... snip ...

No. Pointers also carry (or imply) information about the object type, including alignment requirements. Misaligned access to an item can cause all sorts of unwelcome reactions.

One thing you can do is cast a pointer to an unsigned char*. But not the reverse. Note that you can't dereference a void*.

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.
Reply to
CBFalconer

In C, a byte is just the smallest addressable memory unit. It must hold at least 8 bits, but it can be many more.

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.
Reply to
CBFalconer

... snip ...

Not necessarily so. void* carries all the information, apart from the object type. void* bitpattern is identical with the char* bitpattern, but after that there are no limits.

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.
Reply to
CBFalconer

Well, may be it's just me, but I wouldn't

alignment "addressing".

On some systems. On others you just get garbage values.

I tried to figure out how to do that using gcc, but never I seemed to get the declarations or typedefs right...

--
Grant Edwards                   grante             Yow! We have DIFFERENT
                                  at               amounts of HAIR --
                               visi.com
Reply to
Grant Edwards

I know.

I think the disconnect is in what you meant by "just works". We assumed you meant it resulted in a pointer that could be dereferences. Apparently you meant that it could be cast to someother type, then cast back to the original type and result in the same pointer?

I see. I didn't recognize that point when it was spelled "casting just works".

--
Grant Edwards                   grante             Yow! Oh, I get it!!
                                  at               "The BEACH goes on", huh,
                               visi.com            SONNY??
Reply to
Grant Edwards

You're talking about what the C language standards guarantee. I'm talking about how compilers implement the language. On a byte addressable architecture you can rely on the one I mentioned above. The fact is most programs rely on this whether the standard permits it or not...

Wilco

Reply to
Wilco Dijkstra

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.