Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Writing clean code in C

Name: Anonymous 2012-02-02 2:06

So how do I do it?
C is supposed to be a good and fast language, but all the programs I make end up being clusterfucks of unreadable code

Name: Anonymous 2012-02-02 2:24

Experience. You need to make huge clusterfucks of unreadable code before you get the enlightenment to refactor the code in a more elegant manner.

Name: Anonymous 2012-02-02 2:27

Look around your working area and/or your home. Stuff scattered everywhere, on tables, on the floor? If so, stop using C and use a language that forces you to keep your stuff in the right place. Like C++ or Java. You may not be suited for a language that [ss]lets[/ss] forces you to do your own structuring.

Name: Anonymous 2012-02-02 2:37

Read the code of C masters.

(Extremely) High quality C codebases include:
nginx
SQLite
qmail
dovecot

Alternately, since I myself am a C master, post your self-contained code here and I will rewrite it in an idiomatic style.

Name: Anonymous 2012-02-02 2:40

>>4
How about the OpenBSD codebase?

Name: Anonymous 2012-02-02 3:01

>>5
It's up there but it isn't nginx quality.

Name: Anonymous 2012-02-02 4:21

Search through /prog/ for code posted by frozen void.

It's all very neat and elegant.

Name: Anonymous 2012-02-02 4:37

>>7
trolololololo

Name: Anonymous 2012-02-02 5:03

>>8
Not trolling. His code is extremely elegant and I dare you to post an example of his that isn't. Otherwise fuck off

Name: Anonymous 2012-02-02 9:13

>>9
typedef unsigned long long int u8;

Name: Anonymous 2012-02-02 9:14

It might be beause you're using C, are you going to develop an advanced program, you need to do low-level coding, which is hell for those not used to it.

I prefer Java and C#.

Name: Anonymous 2012-02-02 10:10

If you actually write c99 or c89 and not GNU_C there shouldn't be a problem.

Name: Anonymous 2012-02-02 11:20

>>4
if (a == 0) {
Stopped reading right here.

Name: Anonymous 2012-02-02 12:51

>>13
Not ENTERPRISE enough?
if ((a != 0) == false) {

Name: Anonymous 2012-02-02 12:55

>>14
Error: false is undefined

Name: Anonymous 2012-02-02 13:04

>>15
Try using a real programming language.

Name: Anonymous 2012-02-02 13:19

>>16
U MENA HASKELL?

Name: Anonymous 2012-02-02 13:57

>>17
Haskell is shit.

Name: Anonymous 2012-02-02 14:29

VLAs were a bad addition to C99.

Name: Anonymous 2012-02-02 14:51

>>10
The fuck are you smoking? That type definition makes the code cleaner

Name: Anonymous 2012-02-02 14:59

>>20
u8 would be interpreted by 99.9% of C programmers to mean an unsigned 8-bit quantity. FrozenVoid uses it to mean an unsigned 64-bit quantity. C99 also already has the portable types like uint64_t so why make your own version?

Name: Anonymous 2012-02-02 14:59

>>16
You should consider your own advice

Name: Anonymous 2012-02-02 15:02

>>21
that feel when i'm part of the 99.9%


....................................................................................................
..............-:::-.................................................................................
...........-/+o+///+/-..............................-:/osyyhhhhhddddddhyys+:........................
.........-++/::/++/:/+:........................:+sydmddddddddddddddddmmmmmmmdyo/-...................
......../+/::::::/+/::+/...................:oyhhyyyhhddddddddddddddddddddmmmmmmmmh+-................
......-+/:::::::::/o/::+/.............:+shmmdyssssssssyyhhddddddddddddddddddmmmmdmmds:..............
.....:+/:::::::::::/o/:/o/////++ossyhdmmmddddmmdhysssssssssyhhddddddddddddddddmmmmddmmy:............
....:+/:::::::::::::++::/odmmmmmmmmmmmmddddddddddmmdhsssssssssyyhddddhhyyyssssydmmmmddmmy:..........
...:+/::/::::::::::::+/::+yddddddddddmmmmmddddddddddmmdyssssssssssso++++///::/+yddmmmdddmms-........
..-+/::/+::::::::::::/o::/odmmddddddddddmmmmmddddddddddmmhyssooo+///::+:::::/+shdddmmmdddmmd/.......
..+/:::/+::::::::::::/o/::++oydmmddddddddddmmmmddddddddddmmds/+/::::::+/:::/oyddddddmmmddddmms......
./+::::/+:::::::::::::o/::/+::/odmmddddddddddmmmddddddddddddmds:::::::/+//oyhddddddddmmmddddmmy.....
.+/::::/+:::::::::::::+/::/+::::/smmdddddddddddmmmddddddddddddmh/::::::/+ohdddddddddddmNmmddddmy....
-o/::::/o/::::::::::::/::://::::::ommdddddddddddmmmddddddddddddmdo:://+ossyhdddddddddddmhmmdddmms...
-o/:::::++::::::::::::::::/::::::::smmdddddddddddmmdddddddddddddmms+oosssssshddddddddddmd/mmdddmm+..
.o/::::::++::::::::::::::::::::::::/dmddddddddddddmmddddddddddddddmhssssssssyhddddddddddm:+mddddmd-.
.+/:::::::++/:::::::::::::::::///:::oNdddddddddddddmmddddddddddddddmhssssssssyddddddddddmo.hmdddmNo.
./+::::::::///:::::::::::::::///////+mmddddddddddddmmddddddddddddddmmyssssssssydddddddddN+.+Nddddmd.
.-+:::::::::::::::::::::::::::::::::/mmdddddddddddddmdddddddddddddddmdyyyyhhhhhdddddddddN/.:Nmdddmm-
..//::::::::::::::::::::::::::::::::+mmdddddddddddddmmdddddmmmmmmdddhhyys+/:::-----:::/oy:.-mmmddmN/
..-o/::::::::::::::::::::::::://////hmddddddddddddmmmmmmdddhyyso+++////////:-...............:+shdmN/
...ho/:::::::::::::::::::///+//////omdddddmmmmmdddyssooo++++/////////////++++/-................-:oh+
..-mds/::::::::::::::///+///:://///yhhhhhyssoooo+/+/////////////////////////+++-.:................--
...mmdho/::::/::::///+//:://////////:::::::::::///+//////://+++ooossssssssooo+oo+h..../-............
...mmddmy::::ss+////+////////:::::::://++osssooooo+/::/osshddddmNNNNNNNNdyyhdddNmy+/+os.............
...dmddmd::/o+oyhyo+yho+////:://+oshddmmNNNNNNNNmo/oyss/:oy/-..-/hmNNNmmmh+```.:sNNdso///...........
...ymddmm/::/+syyhdmmNMNmdhyyyyyhdds/:/odMMMMMNNmm+ so .+s-      .NMMMMNNmmy.  `.mo/::/::...........
...omddmN+:::::/++ooydmmmmo:..`/oo/     `mMMMMMMNmmoh. /oo-      -NMMMMMMNmNy+yhhs+oo...............
.../mdddmy:::::::::/yo/oydydy/://++`   `:NMMMMMMmhsyss+o++os:--:sNMMMMMMNNdhdhooos:.................
...:Nmddmd::::::::::/:oho/sh+oossymyoosymNmmdhso+/+/:/+ossyhddddddhhhyso++//:/--....................
...-mmddmm+::::::::::://::+///////++++++++/////////::::::::::::::::::::///:.........................
....dmdddmy:::::::::::::::::::::::////////////::::::::///::::::::::////:-...........................
....hmmddmm/::::::::::::::::::::::::::://////::::::::://///////////::-..............................
....ymmddmNo::::::::::::::::::::://///////::::::::::::::::++///+-...................................
....ommmddmh/:::::::::::::::::::///:::::::::::::::::::::::/+//+-....................................
....ommmddmmo::::::::::::::::::::::::::::::::::::::::::::::/++:.....................................
....omdmmddmd/:::::::::::::::::::::::::::::::::::::::::::::::///:...................................
....smmdmmddmh/:::::::::::::::::::::::::::::::::::::::::////:::/o...................................
....ymmdmmmdmmd+:::::::::::::::::::::::::::::::::::::::::/+/:::++...................................
....mmmmdmmmddmmy/::://///:::::::::::::::::::::::::::::::::::/+/....................................
.../mdmmddmmmdddmmy+/::///+///::::::::::://///++++++++++////+/-.....................................
...ymddmmddmmmddddmmds+///://+++////::::///:::::::////+++/:-........................................
..-mddddmddddmmmddddmmmmdhyyyy+:///+++/////////////::--.............................................
..omddddmmdddddmmmddddddddmmmmd/::::+/..............................................................
.-dydddddmmddddddmmmmdddddddddNs::::o:..............................................................
.sdshdddddmmddddddddmmmmmmddddmm/:::+/..............................................................
/mssyddddddmmmddddddddddmmmmmmmmy:::++..............................................................

Name: Anonymous 2012-02-02 15:07

>>21
We're talking about code elegance. Change u8 to u64 and problem solved. u64 or u8 looks a hell of a lot more elegant than uint64_t.

Name: Anonymous 2012-02-02 15:09

FrozenVoid didn't even know the C standard let alone know how to code elegantly.

Name: Anonymous 2012-02-02 17:21

>>25
ooh I'd like to see an autistic FrozenVoid vs jobless_gallery_programmer showdown

Name: Anonymous 2012-02-02 17:25

>>26
I've never seen jobless_gallery_programmer actually write C code. He appears to know his standard, but not once did I ever see him write his own C code. Also he's a ENTERPRISE JAVA DEVELOPER while FV is just some basement dweller that self-taught himself C in a very poor manner and doesn't know shit about the actual language nor its standard

Name: kodak_gallery_programmer !!qmiXqQhekkGXVVD 2012-02-02 18:57

>>27
I've posted C code on here before. I just did it under Anonymous. And guess what? There wasn't one comment about undefined behavior or about me missing any kind of errors.

Name: Anonymous 2012-02-02 19:10

I've posted C code on here before. I just did it under Anonymous. And guess what? There wasn't one comment about undefined behavior or about me missing any kind of errors.

Name: Anonymous 2012-02-02 19:50

>>28
>>29
I did say you appear to know your standard kodak-san.

Name: Anonymous 2012-02-02 20:45

C is undefined shit.
x86 assembly is KING

Name: Anonymous 2012-02-02 21:02

>>31
STFU Whoopie Cushion Goldberg. Don't you have some farting and roasting pears to do?

Name: Anonymous 2012-02-02 21:11

>>31
x86 assembly is undefined shit.
http://siyobik.info/main/reference/instruction/IDIV
The CF, OF, SF, ZF, AF, and PF flags are undefined.
http://siyobik.info/main/reference/instruction/IMUL
The SF, ZF, AF, and PF flags are undefined.

Name: Anonymous 2012-02-02 21:15

>>32
fuck off and die antijew fucking faggot

>>33
I can deal with that, all it takes is reading the manual for each common instruction.  It's barely a few dozen pages, as opposed to the C fucking standard which is a bloated mess of undefined behaviour.

Name: Anonymous 2012-02-02 21:17

>>34
fuck off and die jew fucking faggot

Name: Anonymous 2012-02-02 21:26

>>35
2deep4u

Name: Anonymous 2012-02-02 21:42

>>34
It's barely a few dozen pages
Maybe if you're writing programs for an XT. After all of the recent extensions and obsolete garbage introduced in the last 30 years it's several thousand. All of this garbage takes up space on the dies and in the minds of programmers but can't be thrown away because when x86 boots it's 16-bit and pretends it only has 1 MB of RAM. The OS needs this 16-bit garbage to unlock the modern instructions. MIPS doesn't have hundreds of pages of legacy garbage and short-sighted decisions like x86 does. The entire user-mode MIPS instruction set can be described in a few dozen pages. Why isn't MIPS popular in desktops today? Because SGI believed Intel about the Itanium and cancelled their MIPS designs. Soon after, they filed for bankruptcy.

Name: Anonymous 2012-02-02 21:45

>>37
SGI believed Intel about the Itanium and cancelled their MIPS designs. Soon after, they filed for bankruptcy.
That's just typical Kol Nidre behavior
All personal vows we are likely to make, all personal oaths and pledges we are likely to take between this Yom Kippur and the next Yom Kippur, we publicly renounce. Let them all be relinquished and abandoned, null and void, neither firm nor established. Let our personal vows, pledges and oaths be considered neither vows nor pledges nor oaths.

Name: Anonymous 2012-02-03 2:50

Avoid structures and pointers whenever you don't absolutely need them.

Before using either, really think as to whether it will make your code easier to read and neater.

Name: Anonymous 2012-02-03 4:29

>>39
The truth lies somewhere between

Rule of Simplicity: Design for simplicity; add complexity only where you must.
Rule of Representation: Fold knowledge into data so program logic can be stupid and robust.

Name: Anonymous 2012-02-03 9:05

>>37
MIPS doesn't have hundreds of pages of legacy garbage and short-sighted decisions like x86 does.
LOL. Anyway, you're completely ignoring the commodification of 3D hardware. Towards the end, SGI didn't offer anything you couldn't get somewhere else.

Name: Anonymous 2012-02-03 9:20

>>37
The bootloader does away with 16-bit mode. The only time you might encounter it is if you want to write a 16-bit interpreter for BIOS code in order to interact with the old BIOS interface, which you shouldn't because EFI is there. The legacy garbage is the manufacturer's problem, not the programmer's.

Name: Anonymous 2012-02-03 9:26

Thread then: Hey guys, how do I write clean C code?
Thread now: HURR MY CPU IS BETTER.

Name: Anonymous 2012-02-03 10:49

>>43
Thread then: Hey guys, how do I write clean C code?
Thread now: Butthurt Jews don't want to admit that Intel Jew chips are trash.

Name: Anonymous 2012-02-03 10:53

>>44
Thread then: Hey goys, how do I write clean C code?
Thread now: Butthurt Goys don't want to admit that x86 is master race.

Name: Anonymous 2012-02-03 11:01

>>45
You don't even know anything about x86. Go suck Shmuel Eden's 16 nm penis somewhere else.

Name: Anonymous 2012-02-03 12:36

>>28
gcc -c -ansi -Wall -I./include read/prog/1328166396 -o obj/prog/1328166396.o
read/prog/1328166396:>>28:71: error: ``guess what?'' is not a question.
make: *** [obj/prog/1328166396.o] Error 1

Name: Anonymous 2012-02-03 12:49

>>46
I know x86 assembly better than you. Overflowing your buffers is a mere keystroke away. Don't anger me, for you shall feel my rootkits.

Don't change these.
Name: Email:
Entire Thread Thread List