just::thread Support Forum
September 10, 2010, 11:40:45 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: just::thread V1.4.1 for Windows and Linux Released
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: warning C4146: unary minus operator applied to unsigned type warnings in v1.0  (Read 5844 times)
JohnWS
Newbie
Posts: 6


View Profile
« on: May 19, 2009, 11:31:42 AM »

Hi

I'm using Microsoft Visual C++ 2008 Express Edition SP1, with just::thread C++ Thread Library v1.0 to compile as the basic sample program below:

// ThreadTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <thread>
#include <mutex>
#include <iostream>

std::mutex io_mutex;

void greeting(const char* message) {
    std::lock_guard<std::mutex> lk(io_mutex);
    std::cout << message << std::endl;
}

int _tmain(int argc, _TCHAR* argv[]) {
    std::thread t(greeting,"Hello from another thread");
    greeting("Hello from the main thread");
    t.join();
    return 0;
}

The compilation succeeds but I get the following warnings:

1>------ Rebuild All started: Project: ThreadTest, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'ThreadTest', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>ThreadTest.cpp
1>c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(109) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(108) : while compiling class template member function 'unsigned int std::__atomic_integral<__itype>::fetch_sub(__itype,std::memory_order) volatile'
1>        with
1>        [
1>            __itype=unsigned int
1>        ]
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(446) : see reference to class template instantiation 'std::__atomic_integral<__itype>' being compiled
1>        with
1>        [
1>            __itype=unsigned int
1>        ]
1>c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(109) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(108) : while compiling class template member function 'unsigned long std::__atomic_integral<__itype>::fetch_sub(__itype,std::memory_order) volatile'
1>        with
1>        [
1>            __itype=unsigned long
1>        ]
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(486) : see reference to class template instantiation 'std::__atomic_integral<__itype>' being compiled
1>        with
1>        [
1>            __itype=unsigned long
1>        ]
1>c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(109) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(108) : while compiling class template member function '__jss::uintmax_t std::__atomic_integral<__itype>::fetch_sub(__itype,std::memory_order) volatile'
1>        with
1>        [
1>            __itype=__jss::uintmax_t
1>        ]
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(506) : see reference to class template instantiation 'std::__atomic_integral<__itype>' being compiled
1>        with
1>        [
1>            __itype=__jss::uintmax_t
1>        ]
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>LINK : C:\ThreadTest\Debug\ThreadTest.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Build log was saved at "file://c:\ThreadTest\ThreadTest\Debug\BuildLog.htm"
1>ThreadTest - 0 error(s), 3 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========


I think Kenneth reported these warnings (amongst other errors) in v0.3 of the library but I've not seen anything else since, which probably means that it's a school-boy error on my part. It doesn't appear to break anything (at least as far as I can tell from simple applications), but does anyone know how to get rid of these warnings?

John
Logged
Anthony Williams
Administrator
Newbie
Posts: 46



View Profile WWW
« Reply #1 on: May 19, 2009, 11:42:16 AM »

Hi John,

You're not doing anything wrong; these warnings are superfluous and warn about valid code in this instance. You can disable the specific warning by adding

#pragma warning(disable:4146)

to your stdafx.h file. I'll fix it for the next build.

Anthony
Logged
JohnWS
Newbie
Posts: 6


View Profile
« Reply #2 on: May 19, 2009, 12:41:59 PM »

Okay. That's good to know.

Thanks Anthony.
Logged
Anthony Williams
Administrator
Newbie
Posts: 46



View Profile WWW
« Reply #3 on: September 04, 2009, 12:27:45 PM »

The latest version should generate far fewer warnings.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!