Thread: pointer casting

  1. #1
    Registered User
    Join Date
    Mar 2004

    pointer casting

    i have am having a problem compilng a simple memory scaning program that checks if there is anything in that address and if there is dicplays what it is this probably breaks alot of rules the way i do this but can somebody help me point out the problem here
    char *ad;
    while(*ad != 0){
    return 0;
    here is the error messages(i dont know what a cast is can someone tell me?
    memscan.c: In function `main':
    memscan.c:6: warning: assignment makes pointer from integer without a cast
    memscan.c:6: parse error before `while'
    memscan.c: At top level:
    memscan.c:9: parse error before string constant
    memscan.c:9: warning: data definition has no type or storage class
    i am running the gnu c compiler

  2. #2
    Registered User
    Join Date
    Mar 2004
    i found one prblem i forgot to put a ; after my pointer assignment but i still get this error
    memscan.c: In function `main':
    memscan.c:5: warning: assignment makes pointer from integer without a cast

  3. #3
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    I saw a prior char pointer and a string literal assigned similar to
    char *c="1";
    but I have never seen it declared the way that you do it.
    try something like.
    char *c;
    char a='1';
    I'm not even sure if this will work.
    I have no compiler.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  4. #4
    Registered User
    Join Date
    May 2004
    char *ad;
    Such a thing requires a cast.
    unsigned char *ad;
    ad = (unsigned char *)1
    However, while arbitrary addresses can be nonportably coerced into pointers, the chances of you using an operating system that fails to use protected mode for user level programs are slim unless you're writing embedded software. In that case you cannot point to arbitrary memory addresses and you'll need to look for another way to scan memory.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. casting contents of pointer?
    By nutsNguts in forum C Programming
    Replies: 8
    Last Post: 11-10-2008, 11:07 AM
  2. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  3. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 09:40 PM
  4. Question About Pointer To Pointer
    By BlitzPackage in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:19 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM