473,795 Members | 3,175 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 16341
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
2482
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
8953
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
3830
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
5638
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
13125
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
2452
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
3888
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
20414
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
9672
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
9519
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
10436
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...
1
10163
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
7538
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
6780
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
5436
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...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
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.