Thread: Error converting to same format?

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    118

    Error converting to same format?

    Here's my latest compilation error:

    error: invalid conversion from 'void (*)(_DNSServiceRef_t*, DNSServiceFlags, uint32_t, DNSServiceErrorType, char*, char*, char*, void*)' to 'void (*)(_DNSServiceRef_t*, DNSServiceFlags, uint32_t, DNSServiceErrorType, const char*, const char*, const char*, void*)'|
    Maybe I'm crazy, but they're the exact same thing, what's the problem?

    FlyingIsFun1217

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    They are not the same note the char* versus const char*

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Looks like it took a set of unwary eyes to spot that; thanks

    FlyingIsFun1217

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Well, it went from understandable to mind(mine)-boggling:

    Changed the code, here's what I get now:

    error: invalid conversion from 'void (*)(_DNSServiceRef_t*, DNSServiceFlags, uint32_t, DNSServiceErrorType, const char*, const char*, const char*, void*)' to 'void (*)(_DNSServiceRef_t*, DNSServiceFlags, uint32_t, DNSServiceErrorType, const char*, const char*, const char*, void*)'
    God I hate trying to work with Bonjour.

    FlyingIsFun1217

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Hmm, since they are 100% the same, you will have to post some code that demonstrates the problem.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Ask and your wish shall be granted

    Code:
    #include "dns_sd.h"
    #include <stdio.h>
    #include <string.h>
    
    void HandleEvents(DNSServiceRef)
    {
        //Placeholder
    }
    
    static void MyBrowseCallBack(DNSServiceRef service,
                                 DNSServiceFlags flags,
                                 uint32_t interfaceIndex,
                                 DNSServiceErrorType errorCode,
                                 const char * name,
                                 const char * type,
                                 const char * domain,
                                 void * context)
                                 {
                                     //#pragma unused(context)
                                     if(errorCode != kDNSServiceErr_NoError)
                                     {
                                         fprintf(stderr, "MyBrowseCallBack returned %d\n", errorCode);
                                     }
                                     else
                                     {
                                         const char *addString = (flags & kDNSServiceFlagsAdd) ? "ADD" : "REMOVE";
                                         const char *moreString = (flags & kDNSServiceFlagsMoreComing) ? "MORE" : "";
    
                                         printf("%-7s%-5s %d%s.%s%s\n", addString, moreString, interfaceIndex, name, type, domain);
                                     }
    
                                     if(!(flags & kDNSServiceFlagsMoreComing))
                                     {
                                         fflush(stdout);
                                     }
                                 }
    
    static DNSServiceErrorType MyDNSServiceBrowse()
    {
        DNSServiceErrorType error;
        DNSServiceRef serviceRef;
    
        error = DNSServiceBrowse(&serviceRef,
                                 0,
                                 0,
                                 "_touch-remote._tcp",
                                 "",
                                 MyBrowseCallBack,
                                 NULL);
    
        if(error == kDNSServiceErr_NoError)
        {
            HandleEvents(serviceRef); //Look up HandleEvents function to learn purpose of it
            DNSServiceRefDeallocate(serviceRef);
        }
    
        return error;
    }
    
    int main(int argc, const char * argv[])
    {
        DNSServiceErrorType error = MyDNSServiceBrowse();
        if(error)
        {
            fprintf(stderr, "DNSServiceDiscovery returned %d\n", error);
        }
        return 0;
    }
    The error is being thrown at line 49, the NULL argument of DNSServiceBrowse while setting DNSServiceTypeError error.

    Thanks again,

    FlyingIsFun1217

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Something compilable please?
    I don't know what the DNSServicePrototype looks like, or what the types DNSServiceRef, etc are.
    According to the error, the function wants a _DNSServiceRef_t*, but what you have is DNSServiceRef, so I can't be sure of what's wrong or where.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Well, it's linking into Apple's DNS-SD library, which is quite complex, so I'll spare you the pain of scrolling through it. It can be found here though, if you'd like to look at it, the only changes being that the initial U/INT* typedefs have been removed because mingw throws errors when trying to compile with them (I added && ! defined(__MINGW32__)).

    That's really the only reason I'm having a problem with this, is that it won't compile after throwing that error every time, so to give you something compilable I can't do (that's my exact problem). I have a feeling my only actual issue though is the lack of the type definitions I referenced to removing, in which case I need to figure out how to get mingw to accept them.

    Thanks again,

    FlyingIsFun1217

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Looking at dns_sd.h, you can see that
    Code:
    typedef void (DNSSD_API *DNSServiceBrowseReply)
        (
        DNSServiceRef                       sdRef,
        DNSServiceFlags                     flags,
        uint32_t                            interfaceIndex,
        DNSServiceErrorType                 errorCode,
        const char                          *serviceName,
        const char                          *regtype,
        const char                          *replyDomain,
        void                                *context
        );
    I'd guess that your MyBrowseCallBack function needs to be marked with DNSSD_API, which is defined as follows.
    Code:
    /* standard calling convention under Win32 is __stdcall */
    /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */
    /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */
    #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)
    #define DNSSD_API __stdcall
    #else
    #define DNSSD_API
    #endif
    I'd think the compiler would give a different warning for a missing __stdcall (if you're even using a compiler that requires it!), but that's the only thing I can see different about the typedef and your function definition.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    My tiny little self-taught brain is starting to lose track of things. What is going on with the typedef? I've never seen one with parameters (?), as if it were defining the void type or something.

    And what do you mean by saying that the function needs to be marked with this type (I assume DNSSD_API is a type?). Where?

    Maybe there's a concept I'm missing out on in C++ that could be briefly explained/linked to?

    Thanks again

  11. #11
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by FlyingIsFun1217 View Post
    My tiny little self-taught brain is starting to lose track of things. What is going on with the typedef? I've never seen one with parameters (?), as if it were defining the void type or something.

    And what do you mean by saying that the function needs to be marked with this type (I assume DNSSD_API is a type?). Where?

    Maybe there's a concept I'm missing out on in C++ that could be briefly explained/linked to?

    Thanks again
    It's the function's "calling convention". See here for details.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Thank you, the perfect reference I was looking for.

    I'll review it, hopefully learn something, and dare I say, return with any more problems.

    FlyingIsFun1217

  13. #13
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Alright, I've read a bit on it, and at least for me, it's a bit of a confusing topic (methods of working at a low assembly level?), but I've added what seems necessary to me to my code:

    Code:
    static void DNSSD_API MyBrowseCallBack(...)
    Now everything compiles fine, but when it comes to linking time, I get two errors:

    obj\Release\main.o:main.cpp|| undefined reference to `DNSServiceBrowse@28'
    obj\Release\main.o:main.cpp|| undefined reference to `DNSServiceRefDeallocate@4'
    This seems odd, as they're in dns_sd.h, which is linked to in my main.cpp. What is it missing? Is this a project setting within the IDE?

    Thanks again

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The functions exist in a separate library, most likely, so you'll have to tell the linker where to find them. There should be a .lib file there. You'll have to tell the compiler/linker to look in it.
    While the prototypes may be in the dns_sd.h, the actual implementation isn't.

    Also, it's weird that GCC doesn't mention the calling convention. It's part of the type, after all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Yeah, and that's kind of what I was afraid of. Bonjour provides a .lib library, but I'll have to find some way to use it within gcc, since it's meant for MSVC. Honestly, if MSVC had as simple of a compiler installation, I would be using it right now :/

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IPv6 zone index format
    By Mario F. in forum Tech Board
    Replies: 0
    Last Post: 10-05-2009, 11:28 AM
  2. Zoom
    By jma619 in forum C Programming
    Replies: 1
    Last Post: 09-13-2009, 05:13 AM
  3. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  4. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 06:25 AM
  5. Seeking Format Advice
    By PsychoBrat in forum Game Programming
    Replies: 3
    Last Post: 10-05-2005, 05:41 AM