Like Tree1Likes
  • 1 Post By Salem

error: invalid conversion from 'const void*' to 'void*'

This is a discussion on error: invalid conversion from 'const void*' to 'void*' within the C++ Programming forums, part of the General Programming Boards category; Hi,I'm getting two errors on my C++ code that I got as an example from the net.The other error is ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    4

    error: invalid conversion from 'const void*' to 'void*'

    Hi,I'm getting two errors on my C++ code that I got as an example from the net.The other error is the initializing argument 3 of 'void SendList(int, Addr4882_t*, void*, long int, int)'..I was wondering if anyone could explain to me what it meant and how to rectify the errors.I have also uploaded pictures to see clearer.. Did I even post the message in the correct forum?? Name:  beginning of my code.jpg
Views: 795
Size:  43.0 KBName:  const void error.jpg
Views: 791
Size:  74.6 KB Please, I need serious help..The code is posted below:
    insert
    Code:
    #include <windows.h>
    #include "Decl-32.h"
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    void gpib_error(int errnum, char *errmsg);  //error-reporting function
    
    const int BUF_SIZE = 1024; //the size of our input/output buffer
    const int NUM_DEVICES = 31;     //maximum number of devices on the bus
    
    int main()
    {
    
      char buffer[BUF_SIZE];
      int i, num_listeners;         //the number of listeners on the bus
      unsigned short address;       //the address of a listener
    /* Arrays of possible instrument addresses, and actual addresses
      The type Addr4882_t is a computer - dependent map to a built - in
      data type that holds the number that is the address of a device. */
      Addr4882_t instruments[NUM_DEVICES], result[NUM_DEVICES];
      SendIFC(0);
    //check for an error
      if (ibsta & ERR)
        gpib_error(1, "Could not send IFC");
      for (i = 0; i < NUM_DEVICES - 1; i++)
        instruments[i] = i + 1;
      instruments[NUM_DEVICES - 1] = NOADDR;
      cout << "Finding all listeners on the bus..." << endl;
      FindLstn(0, instruments, result, NUM_DEVICES);
      if (ibsta & ERR)
        gpib_error(2, "Could not find listeners");
      num_listeners = ibcnt;
      result[num_listeners] = NOADDR;
      cout << "Found " << num_listeners << " devices on the bus" << endl;
      SendList(0, result, "*IDN?", 5L, NLend);
    //check for error
      if (ibsta & ERR)
        gpib_error(3, "Could not send *IDN? to devices");
      for (i = 0; i < num_listeners; i++) {
        Receive(0, result[i], buffer, BUF_SIZE, STOPend);
    //check for error
        if (ibsta & ERR)
          gpib_error(4, "Could not receive from device");
        address = GetPAD(result[i]);
        buffer[ibcnt] = '\0';       //Now output the results
        cout << "Device #" << address << " has ID string: " << buffer;
      }                             //We're done with the program, so take the board off-line
      ibonl(0, 0);
    }
    
    void gpib_error(int errnum, char *errmsg)
    {
      cout << "Error #" << errnum << ": " << errmsg << endl;
      ibonl(0, 0);                  //take the board offline
      exit(1);                      //terminate program
    }
    Last edited by Wahidin Wahid; 04-16-2012 at 07:20 PM.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,527
    Could you please edit out all of the font tags in your post? It's hard to read this.

  3. #3
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    589
    That is C++ code, go out the door take an up and its your first thread on the right.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    > Did I even post the message in the correct forum??
    No, but I fixed it.

    I even fixed the dog-food you called code with something we can actually read.

    > SendList(0, result, "*IDN?", 5L, NLend);
    To fix something like this properly, you would need to make SendList() accept a const void* as the 3rd parameter. There is no reason why an output function should need "write" permission on the data being sent. It's just a poorly defined function.

    This is bad
    SendList(0, result, (void*)"*IDN?", 5L, NLend);

    This is ugly
    strcpy(buffer,"*IDN?");
    SendList(0, result, buffer, 5L, NLend);
    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.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Well, you seem to love cross-posting.

    Oh, and taking code that someone else wrote.

    Someone ban this guy >_<

  6. #6
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Have you tried something like:
    Code:
    char data[] = "*IDN?";
    SendList(0, result, data, 5L, NLend);
    That way the data is not const.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    > Well, you seem to love cross-posting.
    To be fair, that post is nearly a week old with no reply.
    There does come a point where you just have to give up on a forum and seek help somewhere else.

    > Oh, and taking code that someone else wrote.
    Well they did say right at the start
    "Hi,I'm getting two errors on my C++ code that I got as an example from the net"
    laserlight likes this.
    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.

  8. #8
    Registered User
    Join Date
    Mar 2012
    Posts
    4
    oh, I tried what oogabooga said and the error doesn't appear anymore..
    but now I'm getting new errors in the form of undefined errors.... sigh... hmm... is it something that has to do with the header file? should i post the code of that too?? the decl32.h is ridiculously long though....
    I'm trying to understand this from a website GPIB Programming in
    C/C++


    But thanks for all the replies whether they are both useful or not....
    and thank you Salem for fixing my post..

  9. #9
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,527
    Be specific.

    I'm sure that the instructions you linked are right. But it's unfair to make us guess at what the errors actually say.

  10. #10
    Registered User
    Join Date
    Mar 2012
    Posts
    4
    |In function 'int main()':|
    warning: deprecated conversion from string constant to 'char*'|
    warning: deprecated conversion from string constant to 'char*'|
    warning: deprecated conversion from string constant to 'char*'|
    warning: deprecated conversion from string constant to 'char*'|
    |In function `main':|
    undefined reference to `SendIFC@4'|
    undefined reference to `ibsta'|
    undefined reference to `FindLstn@16'|
    undefined reference to `ibsta'|
    undefined reference to `ibcnt'|
    undefined reference to `SendList@20'|
    undefined reference to `ibsta'|
    undefined reference to `Receive@20'|
    undefined reference to `ibsta'|
    undefined reference to `ibcnt'|
    undefined reference to `ibonl@8'|
    In function `Z10gpib_erroriPc':|
    undefined reference to `ibonl@8'|
    ||=== Build finished: 12 errors, 4 warnings ===|

    this is a small section of the header file: (hope it helps)

    Name:  sendifc.jpg
Views: 744
Size:  101.8 KB
    Last edited by Wahidin Wahid; 04-17-2012 at 02:13 AM.

  11. #11
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,527
    Make sure that you did this:
    Your program should now compile fine, however, if you used any GPIB functions, it won't link. That's because we need to add the object file containing the code for GPIB functions to our project. So go to the menu item Project - Add To Project - Files... Change the display to show all files, and navigate back to the same directory as you did for the include file. Then choose the file gpib-32.obj Visual C++ should then happily add the object file to your project, and you can start writing a GPIB program. You should only need to set the include directory once, but every project that uses GPIB must have the gpib-32.obj file added to it.
    Your program compiles but does not link, just like the source you linked mentioned.

    Also, fix that warning if you can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error invalid conversion from ‘const void*’ to ‘void*’
    By Wahidin Wahid in forum C Programming
    Replies: 3
    Last Post: 03-27-2012, 08:18 PM
  2. Invalid conversion from void to char
    By askinne2 in forum C Programming
    Replies: 6
    Last Post: 10-02-2010, 10:41 AM
  3. Replies: 12
    Last Post: 03-27-2009, 02:36 PM
  4. invalid conversion from void* to int*
    By Tropod in forum C++ Programming
    Replies: 10
    Last Post: 01-04-2009, 03:15 PM
  5. Invalid conversion from 'const void*' to 'void*' error
    By prawntoast in forum C Programming
    Replies: 3
    Last Post: 05-01-2005, 10:30 AM

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