File size: 15,191 Bytes
8837177 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
----- --- 92819352 Lets have a C thread. Post what your working on! Show what your interested in now. Last thread: >>92772863 → Wiki: https://wiki.installgentoo.com/wiki/C_Help_and_Discussion IRC: irc.rizon.net channel #/g/chad Don't know how to write C? Start here: K&R PDF: https://files.catbox.moe/80f07b.pdf King PDF: https://files.catbox.moe/7zgskj.pdf Modern C: https://files.catbox.moe/xeb93p.pdf --- 92819429 >>92819352 (OP) Use C++ you fucking cunts --- 92819469 >>92819429 No --- 92819553 >>92819429 Here your sepples private: case T_String: case T_Array() == *R.getAsNumber?)"); return std::string an astral codepoint"); // Case T_Null; assert(Err); for (const UTF32 *Out32 - Codepoints(S.size(reinter &I) continue; return parse as integer OS << "null"; return *L.getAsBoolean() == '\r': return false; return V->getAsNumber(peek())) return *L.getAsNumber(); } const Value(json::Array>())); return OS; } ndentAmount)) I(Newline); return *L.getAsNumber(C, Out); case '{'; } Invalid JSON value::Boolean: case ',': if (C = next()) { if (P.parseValue(json::Array>(std::initializer_list<Value_type *> Elements)) {} void llvm::StringRef K) const Object>().~ObjectKey &K) { if (LLVM_LIKELY((C & 0xFC0) >> 12); M.Type = 0x80 | (Rune & 0xFC0) >> 6); if (LLVM_UNLIKELY(Second)) // If it's not an invalid = [&] { Out.append(/* UTF-8. if (LLVM_LIKELY(isLegalUTF8String(&Res[0]); UTF8 *In8 = reinterpret_cast<const char C : Bytes[] = {next() == 'l') || return try_emplace(); eatWhitespace( break; if (End == S.end() != RHS.find(K); if (isUTF8(llvm::Optional<bool> Object::get(StringRef>(M.as<String: while (isNumber() == 'u' && next() == 'e') || Out.push_back('\n'); Out = SecondByte); return false; } void Value(A.back(C); break; }); if (LHS.size() != '\\' || C == '.'; if (LLVM_UNLIKELY(P + 2 > End || *P : sortedElements; } llvm::None; } llvm::Optional<double>::max_digits from the first >= 0x20) - 'A' + 10 : (C - '0'); : Start; X < P; ++X) { if (Comma) const Value::StringRef K) const Value &Object::getInteger: case 't'; IndentLevel += Indenter &I) const { Invalid codepoint. quote(OS, as<StringRef K) const Object::getString>().~basic_string Res(4 * Codepoints.data()); return true; eatWhitespace(K, nullptr; } --- 92819571 >>92819352 (OP) >King PDF: https://files.catbox.moe/7zgskj.pdf Where can I find the solution for ALL problems? http://knking.com/books/c2/answers/index.html Only has a very small amount of solutions. --- 92819603 >>92819571 The whole point is to do them. Unless you have a class that requires you to do them, you really shouldn't need that. Just do them. you lazy bastard. --- 92819622 >>92819603 Did you actually finish all of them? How difficult were they for you? --- 92819629 >>92819603 What's your problem? I want to compare my solution to a "proper" one. Why do you always expect the worst? I'm a fucking 25yo neet trying to better myself and leave neetdom, I don't have any "classes". --- 92819706 >beej still not in the op i look forward to yet another thread full of questions that beej answers in course. --- 92819732 >>92819706 what the fuck is a beej --- 92819738 >>92819622 I'm actuallying working through chapter 25, which hasn't been too hard. >>92819629 I expect what I see. But do as you wish, I'm certain someone on github has done exactly what you described. I've primarily done code golfing with my code, I used a lot of m4 to produce most of the code I've written. --- 92819774 >>92808507 → # >this is not the 1960s, every OS uses virtual memory and pages are allocated lazily. you can go ahead and mmap a 1GB address - it won't cause excessive memory usage because only the pages that you use will get physically mapped. You seem to be very confused about how memory allocation works in OSes. There is a different between pages actually being allocated (mapped) and being accounted. By allocating excessive memory you might start running OOM with plenty of free memory in the system. Systems that do overallocation might be tolerant to this (at least until you disable it), but Windows, for example, will not like it, as it accounts memory strictly >>92808850 → # Main thread on Unix has no stack limit, same is true for any thread whos stack is mapped with MAP_STACK. Stack grows until it hits another mapping or it hits _optional_ stack size limit. Plus even if stack memory allocation succeeds, there is no guarantee you will be able to call any functions or be able to execute the current one if it decided to expand stack more for locals. So no, alloca cannot fail by returning null. --- 92819800 >>92819732 https://beej.us/guide/bgc Literally just read that and you'll learn C in 4 hours. --- 92819804 >>92819706 I've posted about him already. His C guide is bad. King's book and K&R are x5 better. He isn't descriptive enough. --- 92819915 >>92819774 >By allocating excessive memory you might start running OOM with plenty of free memory in the system. Systems that do overallocation might be tolerant to this (at least until you disable it), but Windows, for example, will not like it, as it accounts memory strictly on windows you can reserve memory before committing it, i.e. you can reserve the address space so that no other allocation gets in the way, and then you can actually map real memory onto that address space. that's why malloc sucks ass because it doesn't distinguish between reserve and commit. for small allocations you can use malloc but for big shit you should use VirtualAlloc or a file mapping instead. --- 92819977 >>92819706 I'll note it down and if I'm still OP next time I'll add it. --- 92820076 >>92819915 You will still have to handle commit failure and unwind stack if running out of memory. And set up exception handlers to do commit on stack overflow. On Windows all of this is possible. But you might start running out of virtual address space if you too generous with it. Not only 32 bit systems are restricted in address space, but also some 64 bit systems - mobile arms might only support 36 bit of virtual address space (or is it a bit bigger? Don't remember). --- 92820117 >>92819804 Not him, but out of curiosity, can you point out an example or two of where he isn't descriptive enough? --- 92820196 >>92820117 He doesn't explain what sequence points or side-effects are. Fine behaviors of C like the logical AND and OR operators purposefully not evaluating their right operands if the left indicates the value of the entire expression aren't explained. You can write C programs whilst not knowing these kinds of details but you're making things harder on yourself by not understanding the full capabilities of C (Which of course can lead to very subtle bugs, although I doubt most people are using expressions w/ side-effects in a logical expression, but you never know...) --- 92820598 Why did they tell us gotos were so evil when they're great for graceful exits with memory freeing? --- 92820660 >>92820598 Who's "they". --- 92820688 >>92820598 Also great when writing SIMD corr and there are many cases that need to be handled. >>92820660 (((They))) --- 92820705 >>92820598 because Djikstra recognized they're potentially abused by incompetent retards, wrote a paper, and everyone took it as law and it became one of those dogmatic things programmers are taught. --- 92820711 >>92820688 >nooooooooooooo i cant be writing bad c coderinooo >it must be da jooossss --- 92820852 >>92820598 (((They))) don't want you to know that gotos compile to more efficient assembly when used as loops instead of actual iteration statements. loopstart:; if (x) goto loopstart; 20 to 30% more efficient. --- 92821063 >>92820598 I don't know who "they" is but the best way to never get good at programming is to listen to other programmers. --- 92821091 >>92820852 wouldn't GCC optimize to that if your using a while loop? It's just jeq and a label either way. --- 92821120 >>92821091 do-while loop, while loop is more complicated --- 92821227 >>92821063 >the best way to never get good at programming is to listen to other programmers so much this --- 92821239 >>92820852 this is literally the same as a do-while loop you fucking nigger >>92820196 >>92820117 Wanking off about knowing what sequence points are doesn't make you a better programmer. Good code doesn't contain anything ambiguous that you have to look twice at to determine where the "sequence point" is. Write C like it's assembly. Each statement does one thing, or a few things in which it's obvious what the order is. --- 92821245 >>92821120 pray tell mr. gupta sir how is it complicated? --- 92821352 >>92821245 It needs 2 jumps: one conditional before the loop body, one unconditional after. But compilers will usually transform while loop into if+do-while, do there will be 2.conditipnal jumps: one before the loop and one after loops body. --- 92821399 >>92821352 loop: if (!cond) goto loopend; /* body */ goto loop; loopend: --- 92821433 >>92821399 Yes, how I described it: 2 jumps. And compiler will never generate that because it is inefficient. Unless exit condition is complex. --- 92822046 >>92821352 >>92821433 Every loop I've ever seen has been turned into one jump and one conditional jump by compilers even when it could be one conditional jump. Example: https://godbolt.org/z/ax8TscbYj --- 92822349 >>92821399 Wouldn't it be better: if (!cond) goto end; loop: ... if (!cond) goto loop; end: --- 92822600 >>92822349 yes --- 92822620 >>92822600 I think >>92821399's is slightly smaller. just a jeq and goto. while mine is two jeq. I'm not sure. I'm trying to learn asm at the moment. --- 92822685 >>92822620 with mine, >>92821399, you're always jumping back at the end, even if the conditional isn't met, just to do another jne at the top, which you might as well have done previously. --- 92824083 Only freechads are welcome here. --- 92824740 >>92820598 There was once a wave of students moving to C from primitive versions of BASIC which didn't have structured programming, just GOTO. They would write horrible code in C, so Dijkstra wrote a paper arguing against their goto-heavy style. Unfortunately, programming has a lot of dogmatic retards (see also Clean Code), so over time the context got lost and "don't overuse goto" became "never ever use goto". --- 92825129 Why the heck C is so bloated? Can we actually get a real simple language? Why do I need 1000 libraries to draw a motherfucking pixel on MY screen??! We should go back to bare metal... --- 92825255 >>92825129 >Why do I need 1000 libraries to draw a motherfucking pixel on MY screen on windows you don't need to use any libraries besides those provided by the system this is a troonix problem --- 92825298 >>92825129 What are you talking about? Its one line of code in C: framebuffer[y*xres+x] = color; --- 92825393 >>92825255 Kys corporate shill. Not about to sacrifice my freedom for some retarded bullshit only relevant to cocksucking WINFAGGOTS WHO CAN'T CODE FOR SHITE >>92825129 YOU BLOODY COCKSUCKER USELESS PIECE OF SHIT INSTEAD OF WRITING YOUR OWN CODE YOU USE SOME CORPORATE POS DRIVER BULLSHIT YOU ABSOLUTE ******. SERVES YOU RIGHT BLOATLORD. I CAN DRAW ANY PIXEL IN ONE LINE. I ABSOLUTELY DESPISE MICROKIKE DIRECTX AND WINAPI SHILLS GNU/LINUX IS JUST SUPERIOR IN EVERY WAY GIVEN YOU THROW CORPORATE BULLSHIT INTO THE RUBBISH BIN IT BELONGS TO ALL YOU BASTARDS DO IS CREATE MORE WORK FOR REAL MEN YOU DONKEYS. SOON VERY SOON YOU WILL CHOKE ON YOUR BLOODY USELESS ABSTRACTIONS AND DIE FOR GOOD --- 92825404 >>92825129 Fuck off Drew, no one is using your gay bunny language. --- 92825428 >>92825129 the problem does not lie with C but the fact that you are retarded. just use unity or some other toddler vidya gaym engine. --- 92825886 >>92825129 let's see you write your own blitters in assembly --- 92825935 >>92819915 >that's why malloc sucks ass because it doesn't distinguish between reserve and commit. Whether malloc distinguishes between "reserve" and "commit" is entirely platform-dependent. --- 92826054 >>92825129 Try using SDL2. Then you'll just need one library. --- 92826096 >>92825935 Mallow doesn't reserve, not in a sense windows uses. There 3 stages of memory allocation you can be dealing: 1. reservation of address space 2. committing memory (memory get accounted as allocated) 3. actual pages being mapped Malloc starts at stage 2. --- 92826136 >>92825393 medication.dll will be injected into your process, please stand by... >>92825935 malloc cannot distinguish between reserve and commit because the API is too shitty and limited for that to be possible. if the C standards idiots had any brain cell they would have 2 functions, mreserve and mcommit. on platforms that don't support 2 stage allocation, mreserve is a no-op. simple as. --- 92826782 >>92826136 >on platforms that don't support 2 stage allocation, mreserve is a no-op. simple as. Reserving cannot be no-op, as it has to return pointer to a memory block that will be commited later. >because the API is too shitty and limited for that to be possible. Shitty API would be exactly what you have described. In most cases people need malloc, for everything else there is mmap --- 92827348 >>92826782 >Reserving cannot be no-op, as it has to return pointer to a memory block that will be commited later. Sorry I have brain fart. On platforms that don't support 2 stage allocation, mreserve and mcommit will do the same thing. --- 92827699 >>92820076 >On Windows all of this is possible. But you might start running out of virtual address space if you too generous with it. Yeah, but it's still an option sometimes. For example, many applications are only ever compiled for x64 anyway, in which case, why not take advantage of the big address space to speed up your app? Not that wasting address space is ever good. Reserving huge address space will waste some memory in the kernel mode because there are data structures created to keep track of reserved pages. So of course, everything used in moderation... --- 92828076 >>92827699 Just get haskellpilled bro. Malloc a terabyte at program start and then rely on overcommit. --- 92828115 Started working on a software-only imgui-like library. Got line/rect drawing and clipping working. Since dear imgui isnt compilable for VC2002/Windows NT4 i have to roll my own crap. Been a fun little project so far. --- 92828167 >>92828076 >Malloc a terabyte at program start and then rely on overcommit nah overcommit is lazy shit design and it causes crashes --- 92828411 >get in thread thinking maybe this will be a less retarded dpt >bunch of people talking nonsense about MMU >leave thread --- 92828657 >>92828411 Be the change you wish to see. These threads are still way better than /dpt/ even at their worst. --- 92828943 >>92825129 its a hardware issue --- 92830831 Page 10 bump --- 92831629 >What Every C Programmer Should Know About Undefined Behavior https://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html |