Results 1 to 3 of 3

Thread: problem compiling

  1. #1

    Default problem compiling

    I am getting a weird compile error:

    I am trying to compile the following code:

    Qt Code:
    1. unsigned short *test;
    2. unsigned addr;
    3.  
    4. test = (unsigned short*) calloc(1, sizeof(short));
    5.  
    6. addr = (unsigned) test;
    To copy to clipboard, switch view to plain text mode 

    note that the above is just an example to illustrate my problem. This compiles fine in visual studio. however, using qmake and make, I am getting the following error:

    error: cast from "short unsigned int*" to "unsigned int" loses precision
    does anyone know what might be causing this? i have never encountered this before.

  2. #2

    Default Re: problem compiling

    I realize if i cast to an 'unsigned long long' the problem is alleviated. it must have to do with the fact that I am on a 64-bit architecture. Still, i do not remember having this problem with g++ (qmake and make) in the past, and it works just find using microsoft compiler.

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem compiling

    many things works just fine in VS compiler which are errors in g++. And, as I checked one of such situation I had, the g++ is right - because VS compiler compiles code which is WRONG in terms of C++ official standard :] In your case you just lost precission due to address size, which was treated as error and in my opinion it is completly right, because your 'addr' will not contain real address so it would unusable and will lead only to seg fault :]
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Compiling Problem qt/embedded 4.4.1 linux scratchbox arm
    By hw in forum Installation and Deployment
    Replies: 0
    Last Post: 11th September 2008, 19:25
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  3. Problem compiling on Solaris 10 with Sun Studio 11
    By marklle in forum Installation and Deployment
    Replies: 2
    Last Post: 30th August 2008, 06:56
  4. Problem cross compiling examples/demo on mips.Qmake/Linking?
    By Cursedbeasty in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 5th July 2007, 10:53
  5. Replies: 7
    Last Post: 28th June 2007, 17:18

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.