Hi I have an array of unsigned chars, like:
MyArray[2048] = {0x00};
For memory-mapping purposes I need to store this array at a specific address
(0xFFFF1199)
How do I declare this?
I cant't do MyArray[2048] = {0x00} @ 0xFFFF1199 :-(
I am using the gnu compiler.
Best Regards
Don
Nov 13 '05
24 16340
On 25 Sep 2003 15:33:28 -0700, Micah Cowan <mi***@cowan.na me> wrote in
comp.lang.c: Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
Don <no**@spam.dk > scribbled the following: Hi I have an array of unsigned chars, like: MyArray[2048] = {0x00};
For memory-mapping purposes I need to store this array at a specific address (0xFFFF1199)
How do I declare this?
You can't. Not under ISO standard C. On some implementations , you can't declare it at all.
Of course you can.
memcpy((void*)0 xFFFF1199, MyArray, sizeof MyArray);
Now, whether or not this does what you want is implementation-defined, but you certainly can do it, if it's doable. The Standard specifically says so.
-Micah
Exactly how does this declare an array of 2048 unsigned characters at
all?
BTW, you're another one who could use a proper signature separator.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Hi,
To declare an array in C:
{
char temp[100] ;
}
Compiler must know its size. If the array is declared in a context the
compiler places it in stack and if a global it places it in heap.
Now how to place an array at a specified location.
I think a static array u can't place it.
With a pointer u can do it.
char * p = (char *) 1000 ;
Now u can use p like u use an array.
p [10] works
Hope this helps,
Regards,
James
Mark McIntyre <ma**********@s pamcop.net> wrote: On Thu, 25 Sep 2003 10:02:07 GMT, in comp.lang.c , Kevin Easton <kevin@-nospam-pcug.org.au> wrote:
Derk Gwen <de******@hotpo p.com> wrote: "Don" <no**@spam.dk > wrote: # Hi I have an array of unsigned chars, like: # MyArray[2048] = {0x00};
If it _has_ to be an array instead of (unsigned char*), many linkers allow you to specify the address of extern objects. You might try checking what your linker permits.
You can do it without linker magic also:
#define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))
When I tried this on my DS9K, it said "moo" and printed out a recipe for making cow from hamburger.
A legal preprocessor directive did all that? I think you need to get a
conforming implementation (I'm reliably informed that one exists for the
DS9000).
- Kevin.
On Fri, 26 Sep 2003 00:00:56 +0200, in comp.lang.c , "Martijn"
<su************ *********@hotNO FILTERmail.com> wrote: #define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))
When I tried this on my DS9K, it said "moo" and printed out a recipe for making cow from hamburger.
liar
No, thats a greek musical instrument, beloved by muses the world over.
I do admit its often strung with cowgut though.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
On Fri, 26 Sep 2003 10:32:04 GMT, in comp.lang.c , Kevin Easton
<kevin@-nospam-pcug.org.au> wrote: Mark McIntyre <ma**********@s pamcop.net> wrote: On Thu, 25 Sep 2003 10:02:07 GMT, in comp.lang.c , Kevin Easton #define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef)) When I tried this on my DS9K, it said "moo" and printed out a recipe for making cow from hamburger.
A legal preprocessor directive did all that?
The message appeared at runtime. The result of the directive is just a
tad implementation defined, I believe.
I think you need to get a conforming implementation (I'm reliably informed that one exists for the DS9000).
The one I have is as conforming as it gets, if somewhat
pathological...
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
Jack Klein <ja*******@spam cop.net> writes: On 25 Sep 2003 15:33:28 -0700, Micah Cowan <mi***@cowan.na me> wrote in comp.lang.c:
Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
Don <no**@spam.dk > scribbled the following: > Hi I have an array of unsigned chars, like: > MyArray[2048] = {0x00};
> For memory-mapping purposes I need to store this array at a specific address > (0xFFFF1199)
> How do I declare this?
You can't. Not under ISO standard C. On some implementations , you can't declare it at all. Of course you can.
memcpy((void*)0 xFFFF1199, MyArray, sizeof MyArray);
Now, whether or not this does what you want is implementation-defined, but you certainly can do it, if it's doable. The Standard specifically says so.
-Micah
Exactly how does this declare an array of 2048 unsigned characters at all?
I never said it did. It does, however, answer the question "I
need to store this array at a specific address." He could use
memset() to better effect, though. And, of course, if he wants to
access it literally as an array, he can always do:
unsigned char (*MyArray)[2048] = (unsigned char (*)[2048])0xFFFF1199;
and dereference MyArray. BTW, you're another one who could use a proper signature separator.
Huh. I'd always been under the impression that it was mainly for
those with big long sigs.
--
Micah
(this better?) ja***********@y ahoo.co.uk (James) writes: Hi,
To declare an array in C: { char temp[100] ;
}
Compiler must know its size. If the array is declared in a context the compiler places it in stack and if a global it places it in heap.
That's not mandated by the standard, so it's
implementation-specific information (even if most existing
implementations happen to implement that way).
Now how to place an array at a specified location.
I think a static array u can't place it.
You can't place any array, regardless of whether static, dynamic
or automatic allocation is used. If you can write to the memory
at location "1000", you haven't allocated at all: it's simply there.
With a pointer u can do it.
char * p = (char *) 1000 ;
Now u can use p like u use an array.
p [10] works
No, you can't use p quite like an array. You use it more like a
pointer-to-char (which incidentally, is pretty much how you use
arrays most of the time). But among other things, you can't make
a call:
foo(&p)
to a function prototyped as:
void foo(char (*p)[1000]);
-Micah
Mark McIntyre <ma**********@s pamcop.net> wrote: On Fri, 26 Sep 2003 10:32:04 GMT, in comp.lang.c , Kevin Easton <kevin@-nospam-pcug.org.au> wrote:
Mark McIntyre <ma**********@s pamcop.net> wrote: On Thu, 25 Sep 2003 10:02:07 GMT, in comp.lang.c , Kevin Easton
#define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))
When I tried this on my DS9K, it said "moo" and printed out a recipe for making cow from hamburger.
A legal preprocessor directive did all that?
The message appeared at runtime. The result of the directive is just a tad implementation defined, I believe.
No, the result of the directive is to introduce a macro called MyArray.
That's all. I think you need to get a conforming implementation (I'm reliably informed that one exists for the DS9000).
The one I have is as conforming as it gets, if somewhat pathological...
Not if merely defining a macro caused unrequested output at runtime.
- Kevin.
James wrote: Now how to place an array at a specified location.
I think a static array u can't place it.
With a pointer u can do it.
char * p = (char *) 1000 ;
Now u can use p like u use an array.
p [10] works
char *p = (char *)10000; is legal C, but C offers absolutely no guarantees
that the address you've forced p to point to is a good place for storing
data. This is the kind of trick that it is best to avoid. For one thing,
it's considerably less portable than Brazil. For another thing, even if
it's legal to write to that space on your system (and it probably isn't, on
modern systems), where do you draw the line? p[100]? p[1000]?
(On the other hand, so-called "badly-behaved" MS-DOS programs used to do
this sort of thing all the time - for an excellent-at-the-time reason which
has become more or less irrelevant nowadays.)
--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Richard Heathfield wrote: char *p = (char *)10000; is legal C, but C offers absolutely no guarantees that the address you've forced p to point to is a good place for storing data. This is the kind of trick that it is best to avoid. For one thing, it's considerably less portable than Brazil. For another thing, even if it's legal to write to that space on your system (and it probably isn't, on modern systems), where do you draw the line? p[100]? p[1000]?
(On the other hand, so-called "badly-behaved" MS-DOS programs used to do this sort of thing all the time - for an excellent-at-the-time reason which has become more or less irrelevant nowadays.)
It's not unusual to see this kind of code used in embedded
systems for which I/O and/or control spaces have been memory
mapped. I agree that it's not portable; but have found it
extremely useful within that limited context.
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dan |
last post by:
hello,
I would to know if it is possible to delete an instance in an array, The
following does not allow me to do a delete.
I am trying to find and delete the duplicate in an array, thanks
for ( j =0; j<MAX ; j++)
{
for ( i =0; i<MAX ; i++)
|
by: Timo |
last post by:
I am trying to get address of myStruct to a string array texts.
I am using M$ Visual C++ 6.0 (this is not OS specific question, though,
this code should also work on 16 bit embedded compiler ;)).
This is my code:
typedef struct
{
const unsigned short a;
const unsigned long b;
|
by: David Mathog |
last post by:
If this:
int i,sum;
int *array;
for(sum=0, i=0; i<len; i++){
sum += array;
}
is converted to this (never mind why for the moment):
|
by: Jens Mittag |
last post by:
Hi!
In my code, I have an array of a structure, which I want to save to a
binary file. When the array is just created, everything works fine, but
when I change contents of the array, saving results in a file, which
doesn't hold the information of the changed array anymore. I dont know why.
Here is the code:
/*
|
by: Alexei A. Frounze |
last post by:
Hi all,
I have a question regarding the gcc behavior (gcc version 3.3.4).
On the following test program it emits a warning:
#include <stdio.h>
int aInt2 = {0,1,2,4,9,16};
int aInt3 = {0,1,2,4,9};
| |
by: anonymous |
last post by:
I have couple of questions related to array addresses. As they belong
to the same block, I
am putting them here in one single post. I hope nobody minds:
char array;
int address;
Questions 1:
Why cannot I do the following:
|
by: Tomás |
last post by:
Some programmers treat arrays just like pointers (and some even think that
they're exactly equivalent). I'm going to demonstrate the differences.
Firstly, let's assume that we're working on a platform which has the
following properties:
1) char's are 8-Bit. ( "char" is synomonous with "byte" ).
2) int's are 32-Bit. ( sizeof(int) == 4 ).
3) Pointers are 64-Bit. ( sizeof(int*) == 8 ).
|
by: gcary |
last post by:
I am having trouble figuring out how to declare a pointer to an array
of structures and initializing the pointer with a value. I've looked
at older posts in this group, and tried a solution that looked
sensible, but it didn't work right. Here is a simple example of what
I'm trying to accomplish:
// I have a hardware peripheral that I'm trying to access
// that has two ports. Each port has 10 sequential
// registers. Create a...
|
by: Abhi |
last post by:
I wrote a function foo(int arr) and its prototype
is declared as foo(int arr); I modify the values of the array in the
function and the values are getting modified in the main array which
is passed also. I understand that this way of passing the array is by
value and if the prototype is declared as foo(int *), it is by
reference in which case the value if modified in the function will get
reflected in the main function as well. I dont...
|
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...
|
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,...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |