>program crashes
>put printf statement after every line
Program crashes
Other urls found in this thread:
>Not fprintf'ing to stderr
You don't have to check every line. Ever heard of binary search?
>program crashes
>switch languages
...
Modularize your code a bit more OP, it makes debugging with printf easier.
>not knowing how to use gdb, lldb, windbg, the visual studio debugger, or the text-mode debugger front-end for [gll]db in vscode
>Virgin slow debugger
>Chad blazing fast printf
>put printf statement after every line
my solution: create a log.h file with a standardized logging method and log class. void utils_log_print()
if ( it == just_werkz) {
printf("Shits werkin' senpai");
}
else {
while (True) {
printf("AAA");
}
}
my way:
if(thing != null){
performOperation();
}
else{
System.out.println("FUCK WHY");
}
>not checking register values after stepping through every line of code
top ASM mate
>Java
>In a thread talking about C
>Not just googling "How 2 if statement C" and winging the rest
I always printf first
gdb as backup
That's because gdb fucking sucks
Unironically this.
Having tests for those modules + printf will help you pinpoint the issue
>Not running code in your head...
Do you fucks seriously not use debuggers? Have you had a job or a large project?
Nearly every programmer I know reaches for printing before debuggers. Debuggers heavily influence the performance of your code, which can make debugging race conditions and other timing issues (with networked services in particular) impossible. Printing has a performance impact too, of course, but much smaller than literally waiting for you, the user, to make a decision at a breakpoint.
There are tons of companies who don't because the environment is too fragile to use one and with distributed nodes you'd have to time the dam debugger on each one and start all over if you fuck up the timing
> mfw serious code has communication timeouts
> mfw debuggers can be crafted and take forever to make for serious code
> mfw not everything has a JTAG debugger port
> mfw billion dollar tech companies advise developers to use fucking tons of printfs.
Thinks this is insane? You're going to be told : Well then, write better code fucboi.
(gdb) break 19
Breakpoint 1 at 0x80483f8: file test.c
(gdb) run
Starting program: /Users/muhdick/node_1
Breakpoint 1, main test.c:19
(gdb) bt
(gdb) c
TIMEOUT TRIGGERED : NIGGER
> Node 1 (hard reset)
> Node 2 (hard reset)
....
> Node 22 (reset)
Have a good day faggot. Try again, i'll wait 1 hour... or use printfs
/thread ...
No one who works on serious code can rely on debuggers and any serious code would require custom debuggers that are cost prohibitive. The only time you get robust debuggers is if the company selling the hardware packages one to get you to buy their product. Even then, as the user above just stated.. All that shit falls apart when you're dealing with timing issues/networked devices.
MODS MODS MODS!!!
Moooods
Print is excellent for debugging.
Problem is if the compile times are large, it's not feasible to add printf and recompile, so you use a debugger.
What's the difference between printf and cout?
Printf is superior in every aspect
>nobody uses bitwise operators hurrr
That doesn't necessarily work, even for simple shit. Undefined behaviour allows a C program to crash before it gets to where the bug is in the source code.
Can you elaborate or give an example?
nothing really, they both just mask file writes to stdout, printf is just older C, cout is some newer cpp
>program crashes
>don't want to debug
>get coffee
>bathroom break
>get another cup of coffee
>contact IT department, tell them my computer crashed
>say I think I need more RAM
>message an intern
>tell him to look over some code, claim its from someone in another department
>write emails to myself with random snippets of code from github to make it look like I'm doing work
>email community manager(boss's new title) random articles about increasing inclusiveness
I'm getting promoted too
>Undefined behaviour allows a C program to crash before it gets to where the bug is in the source code.
literally what the fuck are you even attempting to say?
t. mouse driven developer
what kind of time machines do you write that it starts act nondeterministically because in the future there is a bug
>try catch the whole function
>display "error something"
>request team lead to do it in another sprint
hehe ive been doing if i have huge anime backlog.
blog.regehr.org
Look faggot, I didn't put undefined behaviour in the standard. I'm just telling you some of the implications.
Wouldn't any errors be caught and/or identified on compile?
>step into every function call with debugger
No. What lang do you think this is? Ada?
You might get a warning for some REALLY obvious errors, but nothing else. Undefined behaviour is undefined.
catch (Exception e) {
System.out.println(e);
}
we need a pic for this
Windbg is actually a very good debugger, it makes winapi dev a dream desu