LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-23-2004, 09:21 PM   #1
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Rep: Reputation: 34
assigning memory address to pointer


Hi all,

Can you assign pointers to existing memory adresses such as 0x0004, and read the contents.
It should be possible, but when trying it I always get the error, non-Lvalue assignment
 
Old 04-23-2004, 10:01 PM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
Code:
int *p;
p = (int*)0x0004;
ought to do it. The cast is not absolutely necessary, but probably will avoid warnings in some cases. I'm not sure what you'd do to get the non-Lvalue assignment thing.

It is possibly important that the address is not a *physical* address, and in particular won't correspond to any hardware device. You're really just asking for a seg fault : )
 
Old 04-24-2004, 03:14 AM   #3
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
Yes, after compiling it I get a seg fault
 
Old 04-24-2004, 03:15 AM   #4
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
my intention was to point to a existing hardware address, and view its contents
 
Old 04-24-2004, 03:35 AM   #5
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 417

Rep: Reputation: 31
Linux runs in protected mode, so any memory accesses outside of the memory allocated to a process will cause a segmentation fault. If you need to access system memory or IO ports directly, use /dev/mem or /dev/kmem. They have man pages, man mem, and man kmem.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DHCP: Problem in assigning fixed address to clients libregeek Linux - Networking 6 11-17-2005 11:59 PM
dhcp networking not assigning address quwiltw Linux - Networking 9 12-22-2004 08:25 AM
Assigning site-local ipv6 address to an interface goto Linux - Networking 0 03-24-2003 04:06 AM
Assigning a string to a variable (not a pointer, not a array) JStew Programming 3 11-18-2002 08:13 AM
assigning ip address after install gui10 Linux - Networking 2 03-06-2002 03:36 PM


All times are GMT -5. The time now is 06:49 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration