Questions tagged [signedness]
37 questions
3
votes
3 answers
Why do fstream.read and fstream.write use char and not unsigned char?
As far as I know, read() and write() are there so we can read and write bytes directly from or to a file, and I was taught that the equivalent of a byte in c++ is unsigned char, so why do they take char pointers as parameters?
Also, do take a look…

McLovin
- 3,295
- 7
- 32
- 67
3
votes
3 answers
Are bytes/words/addresses signed or unsigned in Z80 assembler/machine code?
I am making an emulator for Z80 binaries but I cannot find out whether all the integer data types are signed or unsigned from the manual or from google. So are the numbers from registers A,B...HL,BC etc signed or not?
Also, in machine code are the…

Callum Rogers
- 15,630
- 17
- 67
- 90
3
votes
5 answers
Issues about the signedness of char
According to the standard, whether char is signed or not is implementation-defined. This has caused me some trouble. Following are some examples:
1) Testing the most significant bit. If char is signed, I could simply compare the value against 0. If…

Lingxi
- 14,579
- 2
- 37
- 93
2
votes
2 answers
How do I represent C's "unsigned negative" values in Rust code?
I'm calling the ResumeThread WinAPI function from Rust, using the winapi crate.
The documentation says:
If the function succeeds, the return value is the thread's previous suspend count.
If the function fails, the return value is (DWORD) -1.
How…

TheNextman
- 12,428
- 2
- 36
- 75
2
votes
1 answer
Visual Studio 2015: No signed/unsigned mismatch warning in std::make_unique?
I just found a bug in my code and I am pretty baffled that it could happen, since it is a simple signed/unsigned mismatch - which should not happen at all, because I am compiling with warning level 4, warnings as errors. So I tried to reproduce it,…

user2328447
- 1,807
- 1
- 21
- 27
2
votes
2 answers
Pointer targets in passing argument differ in signedness
I've read through similar questions, but I've not been able to find one that helps me understand this warning in this case. I'm in my first week of trying to learn C, so apologies in advance.
I get the following warning and note:
In function…

ogs
- 1,139
- 8
- 19
- 42
2
votes
1 answer
Why does System.Net.IPAddress use signed types?
The methods IPAddress(Int64) and Int32 HostToNetworkOrder(Int32) in System.Net.IPAddress both uses signed types for IP addresses.
This makes it necessary to cast the result from HostToNetworkOrder when using it as a parameter to the IPAddress…

qnyz
- 437
- 4
- 15
2
votes
1 answer
Difference between C# and java big endian bytes using miscutil
I'm using the miscutil library to communicate between and Java and C# application using a socket. I am trying to figure out the difference between the following code (this is Groovy, but the Java result is the same):
import java.io.*
def baos =…

Eric Hauser
- 5,551
- 3
- 26
- 29
2
votes
2 answers
Does the 6502 use signed or unsigned 8 bit registers (JAVA)?
I'm writing an emulator for the 6502, and basically, there are some instructions where there's an offset saved in one of the registers (mostly X and Y) and I'm wondering, since branch instructions use signed 8 bit integers, do the registers keep…

ZimZim
- 3,291
- 10
- 49
- 67
1
vote
0 answers
Is streamsize really the signed counterpart of size_t?
According to std::streamsize at cppreference.com:
It is used as a signed counterpart of std::size_t
What does it mean? Does the standard require that std::is_same_v>? If not, is either guaranteed to…

ByteEater
- 885
- 4
- 13
1
vote
4 answers
The best way in C++ to cast different signedness types each other?
There is an uint64_t data field sent by the communication peer, it carries an order ID that I need to store into a Postgresql-11 DB that do NOT support unsigned integer types. Although a real data may exceed 2^63, I think a INT8 filed in…

Leon
- 1,489
- 1
- 12
- 31
1
vote
3 answers
C comparison 'x < 0' where type of 'x' is arbitrary, i.e. might be unsigned
GIVEN:
A type defined as TheValueT that may be arbitrarily configured, e.g. as uint8_t or int64_. Let there be some code:
TheValueT x = ...;
... do something to 'x' ...
if( x < 0 ) {
/* Do something. */
}
PROBLEM:
It happens that if…

Frank-Rene Schäfer
- 3,182
- 27
- 51
1
vote
4 answers
Unpack signed little-endian in Ruby
So I'm working on some MongoDB protocol stuff. All integers are signed little-endian. Using Ruby's standard Array#pack method, I can convert from an integer to the binary string I want just fine:
positive_one = Array(1).pack('V') #=>…

SFEley
- 7,660
- 5
- 28
- 31
1
vote
2 answers
Can't align "pointer targets signedness"
I've been struggling with this issue for a while where this code
uint8_t *PMTK = "$PSIMIPR,W,115200*1C";
gives me the error
pointer targets in initialization differ in signedness [-Wpointer-sign]
Changing it to only char * or unsigned char *…

Kater
- 63
- 10
0
votes
1 answer
warning: pointer targets in passing argument 3 of 'Proc_Start' differ in signedness
I have a problem with my C code for a stm32 target.
I get this error :
warning: pointer targets in passing argument 3 of 'Proc_Start' differ in signedness
I can't really figure out why, I searched the web for similar topics but none of the…

Snorny
- 3
- 2