garbage

iOS JSON Error: NSDebugDescription=Garbage at end

强颜欢笑 提交于 2019-11-28 08:58:31
问题 This is a really weird bug, when grabbing JSON from my server (which is produced via PHP), I get this error when calling: json = [NSJSONSerialization JSONObjectWithData:kivaData options:kNilOptions error:&jsonError]; JSON Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x178467d00 {NSDebugDescription=Garbage at end.} My (NSData* kivaData) grabs everything perfectly, but it cant parse the JSON. I have run my

Raspberry Pi UART program in C using termios receives garbage (Rx and Tx are connected directly)

守給你的承諾、 提交于 2019-11-28 05:14:58
问题 I have a simple program written in C which uses termios to send a basic string to the Raspberry Pi UART and attempts to read and output the response. The Rx and Tx pins on the Raspberry Pi are connected with a jumper so whatever is sent should be immediately received. Despite the program outputting that it successfully sent and received 5 characters for the chosen string ('Hello'), trying to print the contents of the buffer just produces one or two garbage characters. The program: #include

Unexpected output of printf

て烟熏妆下的殇ゞ 提交于 2019-11-27 05:39:00
int a=5; float b=3.5; printf("%d",b); printf("\n%f",a); Can anyone please tell me why this code is showing unexpected output (garbage\n3.5) Grijesh Chauhan Format string incorrect error, according to your declarations of a and b : printf("%d",b); <-- "b is float" Wrong! printf("\n%f",a); <-- "a is an int" Wrong! -- Undefined behavior should be: printf("%f",b); printf("\n%d",a); Q :- Why you getting that output? It's due to undefined behavior of your code: From INTERNATIONAL STANDARD ©ISO/IEC ISO/IEC 9899:201x 7.16.1 Variable argument list access macros (page 270) 7.16.1.1 The va_arg macro [...

What will be the value of uninitialized variable? [duplicate]

▼魔方 西西 提交于 2019-11-26 17:52:10
This question already has an answer here: (Why) is using an uninitialized variable undefined behavior? 7 answers Possible Duplicate: Is uninitialized data behavior well specified? I tried the following code #include<stdio.h> void main() { int i; \ printf('%d',i); } The result gave garbage value in VC++, while same in tc was zero. What will be the correct value? Will an uninitialized variable by default have value of zero? or it will contain garbage value? Next is on the same #include<stdio.h> void main() { int i,j,num; j=(num>0?0:num*num); printf("\n%d",j); } What will be the output of the

Unexpected output of printf

被刻印的时光 ゝ 提交于 2019-11-26 11:39:50
问题 int a=5; float b=3.5; printf(\"%d\",b); printf(\"\\n%f\",a); Can anyone please tell me why this code is showing unexpected output (garbage\\n3.5) 回答1: Format string incorrect error, according to your declarations of a and b : printf("%d",b); <-- "b is float" Wrong! printf("\n%f",a); <-- "a is an int" Wrong! -- Undefined behavior should be: printf("%f",b); printf("\n%d",a); Q :- Why you getting that output? It's due to undefined behavior of your code: From INTERNATIONAL STANDARD ©ISO/IEC ISO

If a function returns no value, with a valid return type, is it okay to for the compiler to throw garbage?

被刻印的时光 ゝ 提交于 2019-11-26 08:55:34
If a function has a return type other than void , and the function does not return anything, then I guess the compiler returns a garbage value (possibly seen as an uninitialized value). It happens at compile time, so why shouldn't it throw an error? For example, int func1() { return; // error } int func2() { // does not return anything } The second func2 should throw an error, but it does not. Is there a reason for it? My thinking was such that, it can be seen as an uninitialized value, so if we need to throw an error in the second case, then we need to throw error, if an value is

If a function returns no value, with a valid return type, is it okay to for the compiler to throw garbage?

你离开我真会死。 提交于 2019-11-26 08:50:27
问题 If a function has a return type other than void , and the function does not return anything, then I guess the compiler returns a garbage value (possibly seen as an uninitialized value). It happens at compile time, so why shouldn\'t it throw an error? For example, int func1() { return; // error } int func2() { // does not return anything } The second func2 should throw an error, but it does not. Is there a reason for it? My thinking was such that, it can be seen as an uninitialized value, so

What will be the value of uninitialized variable? [duplicate]

折月煮酒 提交于 2019-11-26 03:44:19
问题 This question already has an answer here: (Why) is using an uninitialized variable undefined behavior? 7 answers Possible Duplicate: Is uninitialized data behavior well specified? I tried the following code #include<stdio.h> void main() { int i; \\ printf(\'%d\',i); } The result gave garbage value in VC++, while same in tc was zero. What will be the correct value? Will an uninitialized variable by default have value of zero? or it will contain garbage value? Next is on the same #include<stdio

Is uninitialized local variable the fastest random number generator?

给你一囗甜甜゛ 提交于 2019-11-26 00:31:42
问题 I know the uninitialized local variable is undefined behaviour( UB ), and also the value may have trap representations which may affect further operation, but sometimes I want to use the random number only for visual representation and will not further use them in other part of program, for example, set something with random color in a visual effect, for example: void updateEffect(){ for(int i=0;i<1000;i++){ int r; int g; int b; star[i].setColor(r%255,g%255,b%255); bool isVisible; star[i]