473,883 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array at specific address

Don
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 16358
Morris Dovey wrote:
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.


Oops. Sorry, yes, I'm afraid I was thinking of desktop systems and up. In
the embedded world, hackery of this kind is indeed still invaluable.
Indeed, there are embedded systems nowadays which are far more powerful
than MS-DOS boxes ever were, and perhaps MS-DOS should be thought of as an
embedded system with delusions of grandeur. (I should add that I have a lot
of time for MS-DOS; I regard it with considerable fondness, and indeed
still program for it occasionally.)

--
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
Nov 13 '05 #21
On Sat, 27 Sep 2003 03:59:01 GMT, in comp.lang.c , Kevin Easton
<kevin@-nospam-pcug.org.au> wrote:

No, the result of the directive is to introduce a macro called MyArray.
That's all.


My apologies - I thought you were trying create an array *at a
specific memory location*, like the OP asked. I obviously assumed
therefore that one had to actually do that, instead of merely
'introducing a macro'.....

--
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>
Nov 13 '05 #22
Mark McIntyre <ma**********@s pamcop.net> wrote:
On Sat, 27 Sep 2003 03:59:01 GMT, in comp.lang.c , Kevin Easton
<kevin@-nospam-pcug.org.au> wrote:

No, the result of the directive is to introduce a macro called MyArray.
That's all.


My apologies - I thought you were trying create an array *at a
specific memory location*, like the OP asked. I obviously assumed
therefore that one had to actually do that, instead of merely
'introducing a macro'.....


You can't do that on the DS9k! :)

My intention was merely to show as much of the solution as is possible
in portable C - since the very idea isn't portable there sure isn't a
full answer that's portable.

- Kevin.

Nov 13 '05 #23
On Sun, 28 Sep 2003 08:01:55 GMT, in comp.lang.c , Kevin Easton
<kevin@-nospam-pcug.org.au> wrote:
Mark McIntyre <ma**********@s pamcop.net> wrote:
On Sat, 27 Sep 2003 03:59:01 GMT, in comp.lang.c , Kevin Easton
<kevin@-nospam-pcug.org.au> wrote:

No, the result of the directive is to introduce a macro called MyArray.
That's all.


My apologies - I thought you were trying create an array *at a
specific memory location*, like the OP asked. I obviously assumed
therefore that one had to actually do that, instead of merely
'introducing a macro'.....


You can't do that on the DS9k! :)


Sorry, we were at cross purposes. I thought you were claiming
portability for the macro.
--
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>
Nov 13 '05 #24
>On Thu, 25 Sep 2003, Don wrote:
I cant't do MyArray[2048] = {0x00} @ 0xFFFF1199 :-(
I am using the gnu compiler.

In article <Pi************ *************** ***@drj.pf>
Darrell Grainger <da*****@NOMORE SPAMcs.utoronto .ca.com> writes:... If you have to have it as an array then check with a newsgroup that deals
with your compiler. You can sometimes define a section of data to a linker
section name (.text, .bss. data, etc.) and then instruct the linker to put
that section at a specific memory location. This is highly dependent on
your linker and completely off topic for comp.lang.c.


Assuming he is using the GNU binutils linker as well as the GNU
compiler suite, there is indeed a way to do it. The C code
portion can consist entirely of:

extern char MyArray[2048];

with linker directives to put the known name at the chosen address
and (if needed, and if the target link format is capable) to fill
the chosen address with 2048 zero-bytes. Since the binutils linker
directives are not C, you will have to go somewhere else for that
part. :-)

(For more complex cases, one can also use gcc's __attribute__
extension to assign linker sections, as noted above, but beware:
this is buggy in various versions of gcc.)

In general, it is probably better to access specific regions of
memory or memory-mapped I/O via "volatile unsigned char *" pointers
and the like. But on specific architectures, absolute addressing
modes sometimes generated via the "extern char A[]" method may be
desirable in certain cases. (As you might surmise from the amount
of weasel-wording here, this can get quite dicey. Not only do you
need to know everything about the target CPU and hardware, you also
need to know precisely what comes out of the compiler under each
of its different optimization and code-generation models. With
gcc, for instance, using -fpic or -fPIC could really wreck things.)
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #25

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

Similar topics

18
2488
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++)
8
8956
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;
24
3838
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):
4
5645
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: /*
204
13168
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};
28
2465
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:
1
617
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 ).
12
3894
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...
14
20424
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...
0
9786
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
11125
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
10734
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
7962
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
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5794
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
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4211
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
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.