[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 23
File: 4aX1VW1.png (819 KB, 1282x722) Image search: [Google]
4aX1VW1.png
819 KB, 1282x722
Old thread: >>55274909

What are you working on, /g/?
>>
I'm making a web interface for docker. I'm sure something like that exists already but I wanted to roll my own and see if I could do it.
>>
>>55280913
First for meemory safety.
>>
Writing a game in C. I'm targeting the monitor refresh rate. I do all the work, draw the frame, sleep until just before monitor refresh, then wake up, present the frame, and start working on the next one.

There was some garbage input lag on the mouse cursor since my frames are over 15ms stale. How do I fix this? I'm thinking about drawing the graphics, then drawing redrawing the UI over and over again if the cursor moves in a busy wait loop instead of sleeping. It's not really noticeable if the game is 15ms behind, but the UI needs to be responsive.

Is busy waiting a bad idea or is it fine now since every CPU is multicore?
>>
>>55280992
Yes, there are multiple.
A coworker has one for docker-compose
https://hub.docker.com/r/francescou/docker-compose-ui/

You can check the code for principles.
>>
Writing a decentralized 3D realistic cheese pizza MMORPG where you can be the dirty pedo man, woman, little loli, shota, or trap shota you can't be IRL and molest / get molested freely!
>>
>>55280913
KILL YOURSELF

KILL YOURSELF

KILL YOURSELF

YOU'RE A PATHETIC MENTALLY ILL MANCHILD FAGGOT
>>
>>55281015
looks cool, thanks
>>
>>55280913
What are your thoughts on using chars as counters for very small loops?
>>
lmfao fucking agdg shitkids will still defend the unity engine

even AAA devs can't make good games with it

https://www.youtube.com/watch?v=DL4GXV2XzYE
https://www.youtube.com/watch?v=5PUsnzNfOwQ

umbrella corps is obviously complete fucking shit

and big surprise the controls are shit which is a fault of the engine lmfao kill yourselves idiots

https://www.youtube.com/watch?v=OCabT_O0YSM

and this thread is a bunch of literal fags and sub-110 IQ idiots just look at the OP pic and look at yourselves in the mirror
>>
>>55281009
If you're writing a game, you should be concerned with game logic and gameplay, not loosing time with gritty details of how not to do it wrong. (you're doing it wrong, and it's more complicated than that; good thing we've had libs for 30 years)
>>
>>55281035
Not OP but why would that be a problem at all? I often see char get re-#define'd to uint8 or int8.
>>
>>55281035
dumb as fuck, use an unsigned int which natively fits in a register
>>
>>55281035
For char counter in [A..Z] do
print "I'm a faggot"
>>
>>55281041
t. shitkid who has never made a non-shit game
>>
>>55281034
oh whait, I linked to the image not the code
https://github.com/francescou/docker-compose-ui

sry ;)
>>
>>55281035
200% retarded.
It goes on the stack and the difference in size is negligible. On a 64 bit CPU the registers aren't even optimized for chars. You gain literally nothing except some UB on overflows.
>>
>>55281062
gracias kind anon
>>
>>55281058
I demand a link to your non-shit game.
>>
>>55281009
render without sleeping, use vsync

i think with pc games it's expected to have a little bit of input lag with vsync
>>
>>55281074
i'm not gonna dox myself and how about YOU post your non-shit game retard
>>
>>55281041
If he wants to write his own engine, let him.

>>55281009
The trick is, you need to have 2 different kinds of frames. Frames that poll for input, and frames that draw a new picture on the screen. Pseducode could be something like

while(true) {
pollForInputs();
executeGameLogic();
if (timeToDisplayNewFrame()) {
drawNewFrame();
}
}
>>
>>55281041
I'm not writing a game, I'm writing an engine and porting the backend to openGL 4, D3D11, and Vulkan. It's portfolio bullshit so I'm not using any libraries, but GLFW doesn't handle this either.
>>
>>55281086
I never claimed to have a non-shit game

I had a shit tetris clone, and

>>55281088
>If he wants to write his own engine, let him.
You're right, I guess.
>>
>>55281041
most retarded logic ever
>>
>>55281041
The types of people who spend a ton of time reimplementing such unnecessary are the same people who spend no time on game assets.

Spoiler alert: game assets are more worth the time
>>
>>55281065
Will "size_t" cause the compiler to choose the correct size for a given architecture?
>>
>>55281107
Notch wasted time building a custom engine and no time on game assets.
>>
>>55281118
No, just choose int or unsigned int. Size_t will give you a long long which is wasteful since 64 bit CPUs have 32 bit registers
>>
>>55281107
the types of people who use the unity engine are the same people who spend no time on game assets nor "such unnecessary"

kill yourself
>>
>>55281137
>size_t will give you a long long

no. unsigned int
>>
>>55281107
Pretty sure if you're gonna have quality game assets you've got to be artistically talented or pay someone who is. You can't just hand a programmer a Wacom and expect good shit out of them, even if you give them six months.
>>
>>55281154
???
>>
File: 29529-figure-1.jpg (57 KB, 412x413) Image search: [Google]
29529-figure-1.jpg
57 KB, 412x413
>>55281137
>Size_t will give you a long long
>which is wasteful since 64 bit CPUs have 32 bit registers

What
>>
>>55281165
it's platform dependent but typically i find size_t to be unsigned int

typedef unsigned int size_t
>>
>>55281088
Games are actually very well suited to cooperative multithreading
>>
>>55281174
On 64 bit it's guaranteed to be a 64 bit unsigned int. Which is bad for x86-64 CPUs, where an unsigned 32 bit is faster.
>>
>>55281009
>sleep until just before monitor refresh

Not guaranteed to happen accurately.

Read RetroArch source code.
>>
>>55281137
I'm just looking for an "auto"-esque keyword that the compiler will deduce at compile time, for high performance portability without a bunch of #ifdef everywhere.

I've been using uint8_t for small loops as well. I figured it reduce the probability of cache misses, given that I'm fairly focused on locality in the design overall.

Is this not good reasoning? Should I return to the fundamentals?
>>
>>55281187
my x64 build environment does define size_t as long long. i've been building against x86 because i'm linking against esoteric x86 libraries. you win this round.
>>
>>55281208
I imagine you can use auto for most anything. If you're dealing with the stl, use iterators or range-based loops.
>>
>>55281208
#include <stdint.h>

/*
int_fast8_t
int_fast16_t
int_fast32_t
int_fast64_t

uint_fast8_t
uint_fast16_t
uint_fast32_t
uint_fast64_t
*/


learn C faggot
>>
why am i sitting at work watching some crazy dude talk about CIA nigger brains and random numbers
>>
>>55281065
>"It goes on the stack"
>"On a 64 bit CPU the registers aren't even optimized for chars"

>>55281137
>"Size_t will give you a long long"
>"which is wasteful since 64 bit CPUs have 32 bit registers"


Just going to highlight the two dumbest posts in the thread
>>
>>55281252
Get a grip

You should be at home talking and streaming about CIA nigger brains and random numbers
>>
>>55281292
If you're calling a function in the loop, then your index variable is going on the stack.
>>
>>55281240
>fast
nice meme
>>
>>55281088
That should be:

1) process previous input
2) execute game logic
3) draw new frame
4) poll for input
>>
>>55281320
>2016
>not setting your editor's font color to red to make your code faster
>>
>>55281214

Don't you mean unsigned long long?
>>
>>55281340
poll for input first, you want fresh input
>>
>>55281344
kekked
>>
>>55281354
Jesus fuck C types are retarded. And people claim dynamically typed languages are shit. At least I don't need to type unsigned long long long to get a fucking number.
>>
>>55281354
yes my bad
>>
>>55281366
>At least I don't need to type unsigned long long long to get a fucking number.

There's nothing better than C
>>
>>55281366
it's just size_t or uint64_t or whatever you need

dynamically typed languages ARE shit, there is no rigor to it, they're lacking in performance and are just shittier, they allow for bugs that wouldn't even compile in a statically typed language
>>
>>55281366
the point is that it's close to the CPU, of course the types are retarded
>>
>>55281366
>>55281379
>#include <stdint.h>
There, no need to use stupid names anymore. You can even typedef them like everyone does if you think uint64_t is too long.
>>
>>55281366
>guaranteedreplies.jpg
>>
All these statically typed cucks don't realize assembly is dynamically typed. The ultimate low level and the ultimate high level languages are all dynamic. Static typing is just mindless busywork invented for Pajeet because more lines of code == more $$$$
>>
>>55281411
It's not dynamically typed at all though anon
>>
>>55281411
assembly has types? i thought data was data
>>
>>55281438
Pretty sure the CPU doesn't give a fuck what bits I jam down its registers, anon.
>>
my python3 script shits itself whenever i try to connect to anything via tor, any ideas whats going wrong?
>pycurl.error: (7, "Can't complete SOCKS5 connection to 0.0.0.0:0. (1)")

import argparse
import pycurl
from io import BytesIO
from bs4 import BeautifulSoup
from urllib.parse import urlparse
import os

#default settings
_proxy_url = "localhost"
_proxy_port = 9050
_page_increment = 12
_follow_redirects = True
_useragent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"

def get_file(url):
buffer = BytesIO()
conn = pycurl.Curl()
conn.setopt(conn.WRITEDATA, buffer)
conn.setopt(conn.PROXY, _proxy_url)
conn.setopt(conn.PROXYPORT, _proxy_port)
conn.setopt(conn.PROXYTYPE, conn.PROXYTYPE_SOCKS5)
conn.setopt(conn.FOLLOWLOCATION, _follow_redirects)
conn.setopt(conn.USERAGENT, _useragent)
conn.setopt(conn.URL, url)
conn.perform()
rcode = conn.getinfo(conn.RESPONSE_CODE)
conn.close()
return rcode, buffer.getvalue()
>>
>>55281452
>>55281445
>>55281438
>falling for the bait
>>
>>55281460
stop BAITING us you TROLL
>>
>using an integer type that isn't long long long long long
>>
>>55281466
>fixed size integer
>>
C++ fags, what the shit is this line friending to class my_class?

friend std::ostream& operator<<(std::ostream&, const my_class&);
>>
what does "deploy in the cloud" imply? (like AWS)
does it only work for web apps?
>>
>>55281488
That's disgusting.

If you use private variables, you might be retarded.
>>
>>55281488
an external overload of << that should be invoked when you do
my_class x;
std::cout << x;
for example.

Why?

>>55281508
stfu
>>
>>55281517
Private variables, and by extension friends, are literal cancer. Some real useless OOP bullshit. Structs are better than classes.
>>
>>55281539
Fuck is wrong with them? Everything you can do with all-public structs you can do with private members+friends if you add enough qualifiers, and you can't do unsafe shit so what's the problem?

#define class struct
#define private public
#define protected public

if that's your thing (90% sure it works, last time I tried was weird but I don't see the issue)
>>
Writing a decentralized 3D realistic cheese pizza MMORPG where you can be the dirty pedo man, woman, little loli, shota, or trap shota you can't be IRL and molest / get molested freely!
>>
File: 1441097868324.jpg (9 KB, 222x216) Image search: [Google]
1441097868324.jpg
9 KB, 222x216
>tfw I've internalized the concept of pointers
>tfw I can effortlessly read declarations like void *(*(*f)[])(int *, int *)
>tfw I can make a linked list

Slowly becoming less of a n00b lads.
>>
>>55281573
>tfw I can effortlessly read declarations like void *(*(*f)[])(int *, int *)

function signature syntax is so nasty
>>
>>55281517
Thanks, that makes some sense.

Could you explain
 std::ostream& 
and the & in it ?
>>
is it bad practice to run all my small backend service modules wrapped in a single application? (patch system, error reporting, authentication, etc)
basically the wrapper load a config file to understand which services to run, and then manages any error reporting/statistics gathering without having to write that functionality into every single module
>>
>>55281508
Real C++ is disgusting as fuck, m8.

There is a level when it's beautiful and useful but beyond that the way they write professional libs, etc is seriously fucking sick. It's all a mixture of tons of retarded codewords there for no reason.

inb4 safety, it would be much more safe if it was readable by not just severe autists.
>>
>>55281668
>codewords
you mean templates
>>
>>55281609
It's a reference to ostream, you should know references.
std::ostream& reference_to_cout = std::cout;

Also
friend std::ostream& operator<<(std::ostream&, const my_class&);
doesn't define the function, there should be a definition somewhere, maybe in a cpp file.
>>
>>55281675
I wouldn't mind just templates but the whole __names mixed with const*& static &*::@#$@#%$#%^$& crazy bullshit looks like Chinese after a while.

You really need rain man level autism to read that shit.
>>
>>55281668
C++ is only unreadable if you don't know it, so it shows that you don't know C++. It's as if you were complaining that Lisps are unreadable because OMG PARENS.
>>
>>55281041
lmao retard, use vsync
>>
>>55281702
Thank you.
>>
>>55281712
Twenty bottlecaps have been deposited to your Bethesda Associate Account.
>>
>>55281208
Isn't "register" a keyword in C?
>>
>>55281706
I can read C++ which they teach everywhere but I can't read C++ that coders actually use. And that makes it a bad fucking language.
>>
>decide to reinstall windows to regain my sanic speed
>drivers are broken, won't automatically detect new ones
>Windows update is broken
>only detecting 3 gb of ram (No, I didn't install a fucking 32 bit version of the OS)
Fuck this. I'm DBAN'ing my drive and installing a loonix distro.
>>
>>55281729
kys
>>
File: 1465297400484.jpg (100 KB, 500x500) Image search: [Google]
1465297400484.jpg
100 KB, 500x500
>>55281758
>teachers make the language
>>
>>55281758
Then, again, you're just admitting to not knowing the language.
>>
LEARN ME A HASKELL REAL GOOD
>>
>>55281824
It's not knowable. You literally have to have autism and spend years staring at it on top of that.

>>55281794
They must teach a different language that's how much it sucks.
>>
>>55281747
Yes, but it's useless
>>
>>55281883
lol enjoy your kiddie tier half broken python scripts
>>
>>55281883
You must be joking. Please get a job before speaking on this matter again.
>>
>>55281911
I can write C++ for myself or read clean non-autistic code but fuck the rest of it. Boost autists can seriously fuck off.

I hope Rust or something will take over because C++ is a waste of human resources.
>>
>>55281939
>I hope Rust or something will take over because C++ is a waste of human resources.
it won't because it goes too far with the safety nonsense.
you can't even have mutable global variables without tricks.
>>
File: 1441958444616.png (617 KB, 757x719) Image search: [Google]
1441958444616.png
617 KB, 757x719
Does anyone know of a good crash course for C++ that doesn't assume the reader is Pajeet?
>>
>>55281960
>b-b-but muh thread safety (translation: i'm a clueless webshit that can't into programming lang design)
>>
>>55281960
>it goes too far with the safety nonsense.
People always go too far anyway. The farthest you can go becomes industry standard. That's what fucks C++.

At least Rust is readable.
>>
>>55281974
read this 10,000 page book, the spec and spend 10 years working with it day and night, then if you are the chosen one you might have succeeded in learning sepples
>>
How do I print a uint8 in hex form like 0x00, 0xFF etc?
using std::hex ends up looking strange like ^A or ^B
what is this carat stuff
>>
>>55281573
>tfw I've internalized the horrible C syntax for pointers
FTFY
>>
File: 1439648511159.jpg (116 KB, 469x469) Image search: [Google]
1439648511159.jpg
116 KB, 469x469
Rate my C integer averaging function, without overflowing or widening to a larger integer type:

// n is an int instead of size_t because my calculations need it to be signed,
// and I don't want anything to widen at any point.
int iavg(int n, int arr[static const n])
{
int avg = 0;
// Contains the values that would be rounded away by integer division.
// {positive, negative} respectively.
int round[2] = {0, 0};

for (int i = 0; i < n; ++i) {
avg += arr[i] / n;

if (arr[i] % n != 0) {
round[arr[i] < 0] += arr[i] % n;
}
}

avg += (round[0] + round[1]) / n;

// This is to fix some strange edge cases
// For example: [INT_MAX, INT_MIN], [1, -2]
if (avg < 0 && round[0] == 1 && (round[1] == 0 || round[1] / n != 0))
++avg;
else if (avg > 0 && (round[0] == 0 || round[0] / n != 0) && round[1] == -1)
--avg;

return avg;
}


I'm not 100% if it's completely correct though. I might try to formally analyse it later.
>>
>>55282003
Because uint8 is actually a char so it won't print numbers. You have to cast it to an int with (int)var or static_cast<int>(var) when outputting it.
Or maybe some other shit is going on, idk.
>>
>>55281974
>crash course
No one even teaches cryptic professional level C++ with all its const correctness craziness, etc.

What they teach everywhere is literally a different language.
>>
>>55282036
Quit your bitching and learn Python if it's such a problem for you, you massive faggot
>>
>>55282023
>for (int i = 0; i < n; ++i)
>round[arr[i] < 0] += arr[i] % n;
could overflow for sufficiently large n and with the right input
>>
>>55280913
A javascript game
>>
>>55282055
Too bad you can't quit autism and realize that your beloved C++ is a huge drain on society.
>>
>>55281312
>your index variable is going on the stack
how sure are you about this, dumb shit? do you even know anything about computers?
>>
>>55282056
Yeah, I wasn't too sure about that myself.
Thinking about that now, having an array of size INT_MAX - 2, all filled with INT_MAX, it would overflow. I'll have to think of a way to fix that.
Also, I realised the if statement guarding that particular assignment is pointless.
>>
>>55282072
you're delusional and butthurt that C++ seems too hard for you, C++ is the industry standard for anything that requires performance
>>
>>55281560
>can't do unsafe shit
anon...
>but I don't see the issue
that's because you're literally retarded
>>
>>55281939
You forgot the part where Rust is actually more verbose than C++ and has even more extra tokens that make it "unreadable".
>>
>>55282072
I don't even use C++, just tired of you bitching because apparently readability is the deciding factor in how good a language is.
>>
>>55282056
how do you know? did you previously get raped on that?
>>
>>55282119
I am not the same person, but it is important. When you begin to debug Perl code, then you question who invented that shit.
>>
>>55282099
It's not hard, it's an unnecessary waste of fucking time you retard. What the fuck do you code that you have so much time to waste of syntax autism? It's clearly not math or science related.

> C++ is the industry standard for anything that requires performance

That is the problem. It's a mess built on top of a simpler language from the past century. Time to move on.
>>
File: 3mLydMU.png (70 KB, 243x200) Image search: [Google]
3mLydMU.png
70 KB, 243x200
>>55282036
>const correctness
just put const on things that aren't supposed to change
>>
>>55282099
>seems too hard for you
are you pretending to know c++, webshit?
>>
>>55282137
Sure, but making it the most important factor is retarded. I bet he couldn't name other reasons he doesn't like it other than "muh readability"
>>
>>55282143
or just don't
it's pointless verbosity
>>
>>55282181
kill yourself
>>
>>55282181
If you want to Call by value, sure
>>
>>55282195
>>55282211
shrug
I've been programming in C++ for over a decade and I've never once bothered to write "const"
>>
>>55282103
>that's because you're literally retarded
Yes I am. Please spell it out for me so I can be enlightened, O Chosen One!
>>
>>55282146
It's typical Dunning-Kruger, m8. They don't know that they don't know. Or just assume that they'll learn it all next week.
>>
>>55282218
it's much more readable and helps prevent certain bugs

in const correct code, when you see const you know the variable won't change and you know non-const variables WILL change

in code that isn't const correct the variable declarations tell you almost nothing
>>
>>55282234
>you know non-const variables WILL change
or might change depending on branching
>>
>>55282234
the thing is, how often do you create a variable that "doesn't change" ?
never?
>>
>>55282257
all the fucking time

eg instead of baking a cryptic math expression you can make a const variables with descriptive names like const float speed etc
>>
>>55282257
>the thing is, how often do you create a variable that "doesn't change" ?
>never?
No variable ever changes. You're speaking about an assignable.
>>
>>55282160
What the fuck do you want people to add to C++11, C++14, C++17, etc?

No, it'll have everything. But now the same people could sit down, forget the fucking backwards compatibility and C heritage and design a beautiful new language.
>>
>>55282257
I just use #define when i need a variable that never changes. Yes, I know that's bad practice.
>>
>>55282278
>maximum autism
>>
File: bh.jpg (20 KB, 300x300) Image search: [Google]
bh.jpg
20 KB, 300x300
>>55282293
>hugest butthurt over getting...
>REKT!!!
>>
>>55282270
and with non-const float speed the implication is that speed will be re-calculated or incremented, but with const float speed you know the assigned value is the one and only relevant value
>>
>>55282278
>an assignable
get a load of this weaboo shit!
>>
>>55282270
I don't know, maybe our programming styles or problem domains are so different that I don't run into those problems?
>>
>>55282284
And break every other C++ program, which I'm sure everyone would be happy with.
>>
>>55282284
But what do you think is a beautiful language? D and Rust?
>>
>>55282387
I'm pretty sure the language he talks of is either rust or java, both of which I think are bad.
>>
>>55282398
Not the same person, but I think Rust is pretty ok, but it will remain a meme language (not good enough libraries)
Java should die
>>
working on my javascript debug/testing framework cause im tired of my workmates constantly fucking our api into oblivion

>tfw saw a fat neckbeard walking around with an asian qt at the grocery store
that guy is living the dream
>>
>>55282257
It's in function calls, you don't just write functions when you're professional. You pass arguments by cost references and const pointers. Because that's what professionals do among a million others things that no one teaches to people (because it's actually a waste of time)
>>
>>55282289

Err... in C, #define is pretty standard for compile time constants. It's not bad practice at all. The const keyword makes the most sense for use with pointer arguments as a way to signify that the data will not be mutated.
>>
>>55282412
Personally I think Rust is a better language than Java, but I have some issues with things like globals.
>>
>>55282417
What the fuck are you talking about.
>>
>>55282417
Well then I feel slightly better about myself.
>>
>>55282417

Then you cast away const for some cheeky mutation
>>
>>55282412
>it will remain a meme language (not good enough libraries)

Until there are good enough libraries. There are some already.
>>
File: capture.webm (120 KB, 357x345) Image search: [Google]
capture.webm
120 KB, 357x345
Creating crappy animations in a 100% pure language.
>>
>>55282467
I'm getting a little demo feeling here.
>>
>>55282397
Doesn't matter what I think until most people sperg around C++ simply because that's what they've been doing for a decade or two. Rust is pretty nice.
>>
>>55281051
how would a char not fit
>>
>>55282489
fit -> just the right size, here it's 4-8 times too small. If your assignable is going into a register anyway, never going to memory, and blocking that register entirely, just put in a normal int, don't slam your head against the wall for that kind of microdetail.
>>
>>55281445

Casting between ax and eax is nontrivial, it's the same as storing al in bx and bh in ecx. You can't just use mov, you'll have to get the value out of the register before you store it.

In assembler you have to care (a little bit) how your data is stored at the logical level before you use it
>>
>>55282503
>assignable
t. mental illness
>>
File: xml.png (126 KB, 2000x1835) Image search: [Google]
xml.png
126 KB, 2000x1835
>>55282525
>>
>>55282023
>>55282056
Ok, I updated my algorithm.
Also, I did some random testing on my old one, and it was wrong in a few cases.
However, this new one hasn't failed after tens of thousands of random tests, so it's probably right.

int iavg(int n, int arr[static const n])
{
int avg = 0;
int rem[2] = {0, 0};
int add[2] = {0, 0};

for (int i = 0; i < n; ++i) {
avg += arr[i] / n;

int j = arr[i] < 0;
rem[j] += arr[i] % n;
add[j] += rem[j] / n;
rem[j] %= n;
}

avg += add[0] + add[1];

if (avg < 0 && rem[0] + rem[1] > 0)
++avg;
else if (avg > 0 && rem[0] + rem[1] < 0)
--avg;

return avg;
}
>>
>>55282516
>nontrivial
>You can't just use mov
just how much of a fucking retard are you? how many times do I have to rape your mouth before you know your place and stfu?
movzx eax, ax
movzx bx, al
movzx ecx, bh
>>
>>55282437

In general, when I read C source code, #define is more common than const for things like integer and floating point constants. The majority of times const is used, it's with a const pointer argument.

A variable which is const has no guarantee that is can be known at compile time because it can be given external linkage. With #define, it must be known at compile time, so it is preferable for some things, such as array length -- a common use for integer constants.
>>
>>55282412
>>55282460
C and C++ libraries are compatible with Rust. The problem is that people who would be interested in Rust are still being raised as C++ nerds.
>>
>>55282539
int iavg(int n, int arr[static const n])
{
int avg = 0;
int rem[2] = {0, 0};
int add[2] = {0, 0};

for (int i = 0; i < n; ++i) {
avg += arr[i] / n;

int j = arr[i] < 0;
rem[i] += arr[i] % n;
add[i] += rem[i] / n;
rem[i] %= n;
}

avg += add[0] + add[1];

if (avg < 0 && rem[0] + rem[1] > 0)
++avg;
else if (avg > 0 && rem[0] + rem[1] < 0)
--avg;

return avg;
}

ftfy
>>
>>55282571
Why did you change those j's to i's?
They are supposed to index into an array of size 2.

You clearly haven't tried to understand my code.
>>
>>55282587
oops.
agreed
>>
Does anyone know how to do anything in cmake?
I want to use the QSetting library in a c++ project.
But the project is using cmake.

In qmake I always just use the templates,
but how do I tell cmake to do the right thing?
Or how do I find what to look for?
>>
>>55282467
25 years ago thy would do it in less than 128 bytes
>>
>>55282623

A little old, but might work

https://cmake.org/pipermail/cmake/2010-March/035573.html
>>
>>55282557
#REKT
E
K
T
>>
>>55281208
>I figured it reduce the probability of cache misses
no, the type of your index variable should have no effect on cache misses. Accessing elements 1-100 through an int32 should be just as fast as with an int8.
>>
>>55282704
I imagine what he meant was: by using less memory more things will fit in cache, and therefore he may get less cache misses
>>
In C++, how can I call a automatically call a function within an inherited method?

class Foo
{
public:
void do_stuff() {}
}

class Bar : public Foo
{
public:
void do_stuff() override
{
....
....
}
}


I want it so that whenever I call do_stuff() in class Bar, it calls some other function without me having to write it out.
Is this possible? Am I explaining it well?
>>
>>55282181
good lord
>>
>>55282725
>Am I explaining it well?
No
>automatically call a function
what?
>when I call do_stuff, it calls another function
WTF?

Are virtual functions what you want?
Provide an example of a call and tell where you expect it to jump maybe...
>>
>>55282741
feel free to read more than one post in the chain and point out where your issue is with the statement
>>
>>55282725

>I want it so that whenever I call do_stuff() in class Bar, it calls some other function without me having to write it out.

The only times C++ will ever make a function call implicitly is by constructor or destructor. Stop being a lazy turd and write the function call yourself. It's one fucking line, shithead.
>>
>>55282742
>>55282756
Don't worry lads I was being retarded. Move along.
>>
>>55282756
>Stop being a lazy turd and write the function call yourself. It's one fucking line, shithead.

Is this your new tough love approach?
>>
Why don't people like monad transformers? mtl makes them a breeze to use, and all the alternatives have worse performance and/or break laziness and/or can't prohibit instances that violate laws.
>>
>>55282751
why in the world would I waste more of my time reading posts by someone who doesn't understand the value of immutability? someone who has apparently been programming for over a decade lmao
>>
>using size_t when uint64_t exists
>>
>>55282774
Hey SharpShill, why don't you learn a language that respects your freedom? I liked you better when you were RacketRocket
>>
>>55282795
>Hey SharpShill, why don't you learn a language that respects your freedom?

I'm not a nerd.
>>
>>55282774

Tough love has never been a new approach for me.

Anyways, it's 5:23 in the morning, so I should probably get to sleep.
>>
>>55282801
Sleep is for mortals
>>
>>55282798
Why not? Don't you care about your craft? Come 2020 you'll have to pay Microsoft half a cent every time somebody runs your cloud-based int averager.
>>
>>55282801
If you go to sleep now I'll never forgive you

You're probably not even a real dragon
>>
>>55282722
yes, but using an uint8_t won't make a loop small, the loop is either small enough for an uint8_t or it isn't
>>
>>55282819
Can the cloud even average integers?
>>
>>55282839
no one can
>>
>>55282794
portability and it hints that the variable indicates the size of something
>>
>>55282839
It makes 4chan users solve it as a captcha. Once a consensus emerges about the result, the remote call returns with it.
>>
>>55282819

C# and .NET are free software.

The official Microsoft .NET runtime is MIT licensed
The official Microsoft C# compiler is Apache 2 licensed

It is completely impossible for them to demand royalties on any software produced using these tools.

>>55282794

32 bit Intel still exists. Do you really want to use two registers to store your array length when one would suffice?

>>55282829

Real dragons sleep for ages.

Okay, now seriously. Sun is up. Laptop lid must be shut. No more arguing with retards.
>>
>>55282794
>thinking size_t is always 64-bit
>>
>>55282863
>32 bit Intel still exists. Do you really want to use two registers to store your array length when one would suffice?
size_t on IA32 is still (at least) 64 bytes.

Also, there exists 128-bit registers on IA32.
>>
>>55282863
You're no dragon, wyrm
>>
>>55282863
>not using ax, bx etc. instead of eax, ebx, etc. where possible
>>
C# is obsoleted by F#
Java is obsoleted by Scala
C++ is obsoleted by Rust
JavaScript is obsoleted by TypeScript
>>
>>55282877
>64 bytes
why do you keep talking when you're mouth is slapped over and over again by huge dicks?
>>
>>55282957
Disparaging remark about your sexual inclination
>>
>>55282969
>no bully
come on anon, take it all!
>>
>>55282957
I obviously meant bits, you immature cunt.
>>
File: mongodb.png (27 KB, 413x484) Image search: [Google]
mongodb.png
27 KB, 413x484
Can someone post something interesting? What about nosql databases?
>>
>>55282904
IIRC that's actually slower
>>
>>55282995
>damage control
is your throat sore enough?
>>
>>55282951
>obsoleted
>when you want to interface with existing software
you wouldn't use rust to write a driver for example
>>
>>55283012
You recall wrong.
>>
>>55282995
>obviously meant
did you also mean something else than IA32, worthless sack of shit?
>>
>>55283013
Friendly reminder that you have to be at least 18 years of age to be here.

>>55283031
No
>>
>>55283014
You wouldn't download a car
>>
Working on a C compiler. I just reached the point where I can compile the following file:

int foo(int a, int b)
{
return a ^ b;
}


It gets lexed, parsed, IR is generated, then assembly is generated, then it's assembled, then I generate a relocatable ELF object file. All done from scratch. I've tested linking against it with gcc and it all works correctly. Feels pretty fucking good.
>>
>>55283031
>>55283013
>>55282991
>>55282957
>being this assblasted
How's autism?
>>
>>55283014
Rust would be an excellent choice for writing a driver.
>>
>>55283035
>No
how does it feel to always be wrong and get repeatedly facefucked because of it?
>>
>>55283011
>He fell for the snapchat of databases
RethinkDB is nice.

Although a relational, SQL, ACID DB is almost always the superior solution.
>>
>>55283048
>being this owned
how's your jaw?
>>
>>55283052
What am I wrong about? size_t being at least 64 bit on Intel 32-bit?
>>
>>55283043
>babby made a parser
>>
>>55283054
I laughed my ass off when the article came out that said 'actually, to get good performance with mongo you need to think about your schema'

Glad I never fell for that snake oil
>>
>>55283068
you finally got it, shit stain!
>>
>>55283064
How's your ass? Still need that orthopedic cushion, I see
>>
>>55283076
My fucking sides, do you have a link?
>>
>>55283083
It's 'shitstain'. One word, not two. You're illiterate.
>>
>>55283096
>not a shit stain
>I'm a shitstain tho
top cuck, m8!
>>
>>55283092
I think I misremembered, it looks like it was a talk: https://www.compose.io/articles/mongodb-performance-scalability-schema-design-is-more-important-than-anything-else/
>>
Why is the code below doesn't work? C++ 11
std::vector<Month*> date_vec;

for (int i = 0; i < year_count; i++) {
Month* month_ptr = new Month[12];
for (int j = 0; j < 12; j++) {
month_ptr[j] = new Month(constants::months[j], is_leap_year);
}
date_arr.push_back(month_ptr);
}

auto a = date_arr[i][j]->monthMember;
>>
>>55283087
come on, m80, we all know I regularly rape your ass AND throat, in that order!
>>
>>55283118
Sentences should begin with a capital letter. You're illiterate. Your mouth is like an anus.
>>
File: Screenshot - 270616 - 14:55:38.png (264 KB, 1026x949) Image search: [Google]
Screenshot - 270616 - 14:55:38.png
264 KB, 1026x949
>>55283083
But I'm not wrong you idiot.
>>
>>55283125
That's so fucking obvious m8... Just lrn2thinkbyyourself
>>
>>55283126
I rather think you would struggle to rape a thimble with your meager penis.
>>
>>55283125
>date_vec
>date_arr
>->
>>
>>55283125
month_ptr is a Month*. So month_ptr[j] is a Month. Which means you can't assign new Month... to it, as that has type Month*.
>>
>>55283126
See >>55283145
>>
>>55283151
>>55283147
>>55283125
i made a few typos, yeah. however, there is no syntax error in my code.
>>
>>55283073
Nice reading comprehension.
>>
>>55283152
oh, i see. thanks.
>>
>>55283043
That's pretty neat. Kudos man.

Do you have a github ?
>>
>>55283198
Can I fork your .asm?
>>
>>55283174
>typos
do post actual code, not bullshit. If you need to scrap off irrelevant part, make a standalone program and compile it to check it does present the problem in a compat way

https://en.wikipedia.org/wiki/Minimal_Working_Example
>>
>>55283049
The Problem is: No one is doing it
>>
>>55283145
>can't into 32 bit
you're shit, m8!
>>
>>55283216
It's okay to be wrong anon. We're not judging you.
>>
>>55283145
>not wrong
>completely retarded tho
anon...
>>
>>55282539
try with n = INT_MAX and arr filled with INT_MAX - 1
>>
>>55283223
>maximum damage control
>>
I came up with a new, really minimalist language the other day. I think you can express most things in it. Here's the grammar of its expressions E:

E ::= x | λx.E | E E


WDYT?

I have an idea for a type system for it, but I'm not sure if it's too limiting.
>>
>>55283220
>I don't know C
why do you insist on getting raped then?
>>
>>55283198
Yep, but I haven't uploaded it to github yet because I need to clear copyright first from my employer.
>>
>>55283240
Please tell me where in the C standard the size of size_t is specified as anything but implementation defined?
>>
>>55283154
>See
you don't even know wtf you're talking about but you want me to stop gagging you?
Thread replies: 255
Thread images: 23

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.