unsigned-char

-Wconversion warning while using operator <<= on unsigned char

…衆ロ難τιáo~ 提交于 2020-01-02 01:20:21
问题 When I compile the following code with gcc : int main() { unsigned char c = 1; c <<= 1; // WARNING ON THIS LINE return 0; } I get this warning : conversion to ‘unsigned char’ from ‘int’ may alter its value [-Wconversion] Why ? What is wrong with this code ? Actually, can I really use the oprator <<= on a unsigned char variable ? Compilation command : g++ test.cpp -Wconversion -o test.exe 回答1: This is a valid warning: c <<= 1; is equivalent to: c = c << 1 and the rules for << say that the

How to define swig typemap for returning unsigned char* back to java

久未见 提交于 2019-12-30 07:24:29
问题 I have a Java Application that calls a c library for performing crypto functions. This is a custom library implemented in c that we need to use from some Java programs. I need a way to define a SWIG typemap that will allow me call a function passing bytearray from Java and treat it as an unsigned character pointer in C function where c function fills data and returns it to java Excerpt of my present unhappy interface file is as follows %module CryptoFacade %pointer_functions(int, intp);

Bytewise reading of memory: “signed char *” vs “unsigned char *”

送分小仙女□ 提交于 2019-12-28 05:38:15
问题 One often needs to read from memory one byte at a time, like in this naive memcpy() implementation: void *memcpy(void *dest, const void *src, size_t n) { char *from = (char *)src; char *to = (char *)dest; while(n--) *to++ = *from++; return dest; } However, I sometimes see people explicitly use unsigned char * instead of just char * . Of course, char and unsigned char may not be equal. But does it make a difference whether I use char * , signed char * , or unsigned char * when bytewise reading

What is the maximum allowed size of an “unsigned char” array in Visual C++ 6.0?

狂风中的少年 提交于 2019-12-25 11:59:21
问题 For working with graphics, I need to have an array of unsigned char. It must be 3 dimensional, with the first dimension being size 4, (1st byte Blue, 2nd byte Green, 3rd byte Red, 4th byte Unused). A simple array for a 640x480 image is then done like this: unsigned char Pixels[4][640][480] But the problem is, it always crashes the program immediately when it is run. It compiles fine. It links fine. It has no errors or warnings. But when it's run it immediately crashes. I had many other lines

unsigned char pointer in C#?

社会主义新天地 提交于 2019-12-24 19:08:17
问题 In the middle of translating some code from C++ to C#, I found this, unsigned char *p = m_pRecvBuffer + 5; unsigned int noncelen1 = *p * 256 + p[1]; How do I translate this into C#? m_pRecvBuffer is a char-array, however I store it as a byte-array. 回答1: Something akin to byte[] p = new byte[m_pRecvBuffer.Length - 5]; Array.Copy(m_precvBuffer, p, m_pRecvBuffer.Length - 5); uint noncelen1 = p[0] * 256 + p[1]; But in that case I don't think you actually need to use an array copy. Just using uint

uint8 little endian array to uint16 big endian

╄→гoц情女王★ 提交于 2019-12-24 01:17:45
问题 In Python2.7, from an USB bulk transfer I get an image frame from a camera: frame = dev.read(0x81, 0x2B6B0, 1000) I know that one frame is 342x260 = 88920 pixels little endian, because that I read 2x88920 = 177840 (0x2B6B0) from the bulk transfer. How can I convert the content of the frame array that is typecode=B into an uint16 big endian array? 回答1: Something like this should do the trick: frame_short_swapped = array.array('H', ((j << 8) | i for (i,j) in zip(frame[::2], frame[1::2]))) It

What is the difference between char and unsigned char?

不羁岁月 提交于 2019-12-23 17:43:16
问题 (Edited change C/C++ to C) Please help me to find out a clean clarification on char and unsigned char in C. Specially when we transfer data between embedded devices and general PCs (The difference between buffer of unsigned char and plain char ). 回答1: You're asking about two different languages but, in this respect, the answer is (more or less) the same for both. You really should decide which language you're using though. Differences: they are distinct types it's implementation-defined

C++ Converting a float to an unsigned char?

落花浮王杯 提交于 2019-12-21 18:57:33
问题 I'm new to C++, and doing a bit of googling I thought sprintf would do the job, but I get an error upon compiling that I can't convert between an unsigned char and a char . I need an unsigned char because I am going to print to an image file (0-255 RGB). unsigned char*** pixels = new unsigned char**[SIZE]; vector<float> pixelColors; ... sprintf(pixels[i][j][k], "%.4g", pixelColors.at(k)); (pixelColors has size of 3 and 'k' refers to a 'for loop' variable) 回答1: I'll guess that the floats are

Any compiler which takes 'char' as 'unsigned' ?

老子叫甜甜 提交于 2019-12-19 07:55:27
问题 Is there any C compiler which takes the default type of char as unsigned unless explicitly mentioned by the user in the file or project settings? /Kanu_ 回答1: GCC does. But only when compiling for platforms where an unsigned char is the convention, including ARM linux[*]. When GCC compiles for x86, the default is for char to be signed. [*] Or at least it has been in the past. For all I know linux has switched to a different default ABI on ARM since. Update '2013: ARM compilers (gcc, clang) for

for (unsigned char i = 0; i<=0xff; i++) produces infinite loop

天涯浪子 提交于 2019-12-18 09:02:52
问题 Why does the following c code end up in an infinite loop? for(unsigned char i = 0; i <= 0xff; i++){} It is the same result with: for(unsigned char i = 0; i <= 0xff; ++i){} In which way do I have to modify the code, to get it working as expected (without using int or unsigned int datatype)? 回答1: A typical for loop relies on being able to detect the termination condition after the last iteration of the loop. In your case, as other answers have pointed out, i <= 0xff is always true (given that i