accessing Memory location

This is a discussion on accessing Memory location within the C Programming forums, part of the General Programming Boards category; how can I access a particular memory location like 0x417 & 0x418. I basically want to work with the shift ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    21

    accessing Memory location

    how can I access a particular memory location like 0x417 & 0x418.

    I basically want to work with the shift & toggle keys information.

    and could anyone help me out how can I change the particular bits in a byte.

    if u have any reference sites or so.....do tell me please..

    ur help will be highly appreciated

    a newcomer

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    I think most c compilers allow something like

    char* p = (char*)0x417;

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Running this code on any machine except real DOS is likely to either not work at all, or cause the OS to terminate your program.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    21
    Thanx Salem,

    But can u get me some more appropriate help or code for the problem.
    To be more precise I want to manipulate these bytes or you can say read from the location so please tell me the method or the appropraite help place where I can find the solution.



    bye n thanx for the consideration

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    21
    hi Salem,


    I'm using VC++6.0 on windows98


    thanx for the help

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Let me do a brief synopsis on what is a potentially long answer. Since Windows (or any OS) is controlling what memory is allocated to which variable there is very little use for doing this. Items such as hardware have a static memory location and you would need to call the memory location for doing something such as talking to the printer or the monitor. The c/c++ libraries of functions have done much of this for you already. For instance, printf sends all input to stdout, which is set to the memory location of your monitor. Now Windows, is very protective about what you are accessing. In a windows program you can't actually talk to the video card. For doing such a task you could use DOS (which requires a new compiler) but even better yet, use assembly. That would still require a new compiler but in asm you can do what ever the hell it is that you want to do.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    You can't directly access memory in any windows program -- any attempt to access memory outside of your program's allocated memory will cause a segmentation fault, because of how windows manages memory.

    Under DOS, you can do this easily, and in fact MUST do this to gain low-level access to various devices.

    You can do this, but only if you use a compiler which allows you to compile a pure DOS program (a windows console program will NOT work, because these are still windows applications, and must not violate the memory access rules that Windows imposes).

    However, you CAN do this, either in C/C++ compiled for true DOS, or in assembly, and then run the program in Windows. I've done this before when I needed ultra low level access to a port (where I needed to control it on a pin by pin basis). I just ran the program, which is a pure DOS C++ program, under win9x and it seems to work just fine.

    Unfortunately for you, your compiler won't compile a true DOS program. So, you'll need to get a compiler which will do DOS programs.
    Last edited by The V.; 10-10-2001 at 02:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing variables with memory address
    By ITAmember in forum C Programming
    Replies: 54
    Last Post: 06-28-2009, 03:35 AM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. allocate apecified memory location for a c variable
    By BharathKumar in forum Linux Programming
    Replies: 5
    Last Post: 06-01-2007, 03:47 PM
  4. Accessing a certain Memory Location
    By bhuwan in forum C Programming
    Replies: 17
    Last Post: 09-12-2005, 02:51 PM
  5. Accessing memory directly
    By YALINI in forum C Programming
    Replies: 0
    Last Post: 08-30-2001, 11:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21