Results 1 to 5 of 5

Thread: help

                  
   
  1. #1

    Default help

    i need alittle help with this code

    Code:
    #include <iostream>
    
    using namespace std;
    
    void main()
    {
    char c = 'a';
    char *ptr = &c;
    
    cout << (int)&c <<endl;
    cout << (int)*ptr <<endl;
    	
    c= 'b';
    *ptr = 'd';
    cout << 'c' << endl;
    }
    i get this error

    Code:
     
    : warning C4311: 'type cast' : pointer truncation from 'char *__w64 ' to 'int'
    Compiling manifest to resources...
    Linking...
    i was following a tut from 3d buzz but they used visual c++ 03 i have the 05 version i dont no if that will make it not work thanks for the help

  2. #2
    DCEmu Coder splodger15's Avatar
    Join Date
    Jun 2006
    Location
    London
    Age
    33
    Posts
    4,123
    Rep Power
    92

    Default

    I dont know much about c++ but hasnt it all got to be on seperate lines

    PSN ID: splodger15

  3. #3
    DCEmu Old Pro
    Join Date
    May 2006
    Posts
    1,073
    Rep Power
    72

    Default

    it probably is splodger, last time i tried using the 'code' tags it put it as a block of code rather than seperate lines

  4. #4
    DCEmu Coder PSPKOR's Avatar
    Join Date
    Apr 2006
    Location
    England
    Age
    35
    Posts
    184
    Rep Power
    67

    Default

    Its fine to put the code where ever you want as long as you have the {} at start and end.

    Can you not double click on the error and it should show you where abouts the error is. Cant help no more than that as I've only just started learning myself.
    LEARN, MASTER and ACHIEVE!!
    'Bruce Lee'

  5. #5
    DCEmu Newbie
    Join Date
    Dec 2005
    Posts
    10
    Rep Power
    0

    Default

    Looks like your warning is coming from the fact that your are using a 64 bit machine whereas the tutorial was probably originally written for a 32 bit machine.

    On your machine the character pointer is 64 bits and the int is still 32 bits, so to get rid of the message cast the pointer to a long int instead of just an int.

    cout << (long int)&c <<endl;

    Now as for the tutorial in general, I question some of it...maybe it gets built upon to explain things further...

    char c = 'a';
    char *ptr = &c;
    cout << (int)&c <<endl;

    /*why are they casting the below to an int? This is the data the pointer actually points to...so they are casting a char to an int...so you get the integer representation of 'a'...take off the typecast and you get 'a' printing out, which makes more sense to me. But like I said, maybe they expound on this and change it later or something...*/
    cout << (int)*ptr <<endl;

    c= 'b';
    *ptr = 'd';
    /*And here, this just prints out 'c'. Is this a typo? Anyway remove the quotes to get it to print the value of the variable c which at this time is 'd'.*/
    cout << 'c' << endl;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •