Microsoft Visual C++ compiler, cast problem?

This is a discussion on Microsoft Visual C++ compiler, cast problem? within the C Programming forums, part of the General Programming Boards category; I am a beginner at programming, but I am slowly making progress. I was wondering if someone would be able ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    5

    Unhappy Microsoft Visual C++ compiler, cast problem?

    I am a beginner at programming, but I am slowly making progress. I was wondering if someone would be able to help me out with what I believe to be a casting problem. I have attached a small program that is used to read inputs/outputs on an ISA card (home project kit). The program that is attached will compile for the original programmer but he used a different compiler ( I would like to stay with Microsoft Visual C++). I did find the correct way to use Sleep() on FAQ page and also the _inp statement. When I tried to compile this program I get 3 warnings which say "warning C4761: integral size mismatch in argument; conversion supplied". When I highlight the first line of code with a warning "return ((_inp(switch_port) >> (input + 3)) & 1) ^ 1; // yes, return using switch_port" and press the F1 key. I get directed to the "Return Statement" definiton. I thought that trying to change this line to " return ((_inp((int)switch_port) >> (input + 3)) & 1) ^ 1; // yes, return using switch_port " would fix the error but it didn't. Am I way off of course here? Any help with this problem would be greatly appreciated. Thanks again for the wonderful support that the users of this site give to everyone to help out others with their problems.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    did u forget something??
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    What does '_inp' actually return (a byte)?
    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
    Nov 2001
    Posts
    5

    Oops, I forgot to attach the file.

    Yes, _inp checks a byte and then returns an int. At least I thought it did. I remembered to attach the file this time. Thanks Stoned_Coder and Salem. I am sure glad that I read the FAQ's before I posted. I sure know what can happen when you ask something like "How to clear the screen" before reading what you need to.

    Where do the attachments show up at on the board? I didn't see the file that I attached. So, here is the program. Thanks alot for your responses. I greatly appreciate your time!

    // experi2.c

    #include <stdio.h> // contains prototypes for printf() and puts()
    #include <conio.h> // contains prototypes for inp() and kbhit()
    #include <windows.h> // contains prototyped for Sleep()

    // local prototypes
    int is_switch(int input);
    void get_port(void);
    void set_up_ppi(void);

    unsigned int base;
    unsigned int switch_port;

    void main(void)
    {
    int x,y;

    get_port(); // get the value of the base Port Address

    set_up_ppi(); // set up ppi_porta = out, ppi_portb = in, ppi_portc = out

    switch_port = base + 0x18;

    while(1)
    {
    if(kbhit()) // "keyboard hit" -- a compiler function that sees if a key has been
    break; // pressed. We will break out of the while() loop if a key is pressed.

    puts(""); // puts("") will put a new line on the screen
    for(x=0; x<7; x++) // 0 through 6 -- purposely use 0 to produce an error
    {
    y = is_switch(x);
    printf("x=%02d y=%02d|",x,y); // don't print a new line yet
    }
    puts(""); // puts("") will put a new line on the screen
    // after all 7 items have been printed

    for(x=7; x<13; x++) // 7 through 12 -- purposely use 12 to produce an error
    {
    y = is_switch(x);
    printf("x=%02d y=%02d|",x,y); // don't print a new line yet
    }
    puts(""); // puts("") will put a new line on the screen
    // after all 6 items have been printed

    Sleep(3000); // sleep -- compiler function -- wait one second
    // so printed lines can be seen
    // remark sleep out or delete it for full speed

    } // end while(1)

    } // end main()


    /*
    The following are known only to the functions that follow. They
    can't be modified or even accessed by anything above this point.
    Their scope is from here to the end of the file.

    */

    unsigned ppi_porta;
    unsigned ppi_portb;
    unsigned ppi_portc;


    // ================================================== ==============
    // is_switch
    // 1. Return -1 error indicator if the input
    // is less than 1 or greater than 11.
    //
    // 2. If there is a fall-through from the above and the input
    // is less than 4, return the status based on switch_port.
    //
    // 3. If there is a fall-through from both of the above, then
    // return the status based on ppi_portb.
    // ================================================== ==============
    int is_switch(int input)
    {
    if(input < 1 || input > 11) // if the input is less than 1 or greater
    return -1; // than 11, then return -1 showing an error

    if(input < 4) // else, we fall through the above and see if less than 4
    return ((_inp(switch_port) >> (input + 3)) & 1) ^ 1; // yes, return using switch_port


    return ((_inp(ppi_portb) >> (input - 4)) & 1) ^ 1; // fell through "if(input < 4)"
    // so >= 4 (greater than or equal)
    // so use PPI Port B

    } // end is_switch()


    // Get the port. This will grow into an
    // auto-detect function in the future.
    void get_port(void)
    {
    base = 0x300;
    switch_port = base + 0x18;
    ppi_porta = base + 0x20;
    ppi_portb = base + 0x21;
    ppi_portc = base + 0x22;
    } // end get_port()


    // Set up the ppi in mode 0.
    // Make Port A an output, Port B an input and Port C an output.
    void set_up_ppi(void)
    {
    unsigned control = base + 0x23;

    _outp(control, 0x82); // a = out, b = in, c = out

    } // end set_up_ppi()

    // end experi2.c
    Last edited by jonnie75; 11-07-2001 at 07:39 PM.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > return ((_inp((int)switch_port) >> (input + 3)) & 1) ^ 1;
    I would suggest you write the code something like this
    Code:
    int a = _inp(ppi_portb);
    int b = input + 3;
    return ( ( a >> b ) & 1 ) ^ 1;
    Then see which line it complains about
    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.

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    5
    >I would suggest you write the code something like this
    Thanks Salem, I will give it a shot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Apps that act "differently" in XP SP2
    By Stan100 in forum Tech Board
    Replies: 6
    Last Post: 08-16-2004, 10:38 PM
  3. MS Visual C++ 6 wont include vector.h in a header file
    By bardsley99 in forum C++ Programming
    Replies: 9
    Last Post: 11-06-2003, 11:05 AM
  4. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM
  5. MS visual c++ 6 compiler problem
    By buck71 in forum C Programming
    Replies: 2
    Last Post: 10-30-2001, 03:09 AM

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