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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 319
Thread images: 26

What are you working on, /g/?

Previous thread: >>62034793
>>
First for shitposting
>>
{-# LANGUAGE PolyKinds, TypeFamilies, RankNTypes, FlexibleInstances #-}
-- -XPolyKinds -XTypeFamilies -XRankNTypes -XFlexibleInstances

import Data.Functor.Identity
import Data.Functor.Compose
import Control.Monad
import Control.Comonad

data Natural f g = Natural { getNatural :: forall a. f a -> g a }

class Comonoid m where
comappend :: m -> (m, m)

comempty :: a -> ()
comempty = const ()

class Monoidal (m :: k) where
type Product m :: k -> k -> k
type Exponen m :: k -> k -> *
type Identit m :: k

memptyLike :: (Exponen m) (Identit m) m
mapendLike :: (Exponen m) ((Product m) m m) m

class Comonoidal (m :: k) where
type Product m :: k -> k -> k
type Exponen m :: k -> k -> *
type Identit m :: k

comemptyLike :: (Exponen m) m (Identit m)
comapendLike :: (Exponen m) m ((Product m) m m)

instance Monoid m => Monoidal m where
type Product m = (,)
type Exponen m = (->)
type Identit m = ()

memptyLike = const mempty
mapendLike = uncurry mappend

instance Monad m => Monoidal m where
type Product m = Compose
type Exponen m = Natural
type Identit m = Identity

memptyLike = Natural (return . runIdentity)
mapendLike = Natural (join . getCompose )

instance Comonoid m => Comonoidal m where
type Product m = (,)
type Exponen m = (->)
type Identit m = ()

comemptyLike = comempty
comapendLike = comappend

instance Comonad m => Comonoidal m where
type Product m = Compose
type Exponen m = Natural
type Identit m = Identity

comemptyLike = Natural (Identity . extract)
comapendLike = Natural (Compose . duplicate)
>>
>>62037763
second for actual programming discussion
>>
File: Bokuxs5.gif (124KB, 590x333px) Image search: [Google]
Bokuxs5.gif
124KB, 590x333px
>>62037778
>7778
fucking loser
>>
>>62037790
tl;dnr
instance Monoid m => Monoidal m
instance Monad m => Monoidal m
>>
File: 0d6.png (595KB, 600x597px) Image search: [Google]
0d6.png
595KB, 600x597px
>>62037778
>>
>>62037791
install gentoo
>>
File: akari racist.png (196KB, 413x434px) Image search: [Google]
akari racist.png
196KB, 413x434px
Go to any C project makefile and change gcc to g++.

Post how many compile-time errors you get.
>>
>>62037823
What the fuck? That makes no sense.
You may as well just replace it with a Fortran compiler and see how many you get.
>>
>>62037823
What do you mean, you're still not using clang by default?
>>
>>62037823
If you get any, you're writing shit C.
>>
File: 1476548516650.jpg (232KB, 772x525px) Image search: [Google]
1476548516650.jpg
232KB, 772x525px
Fresh OC
>>
>>62037857
good*
>>
>>62037790
>>62037815

if you simplify it and associate the types with the kind instead, and use type operators, you can get

memptyLike ::    I    ~> m
mapendLike :: (m * m) ~> m
>>
>>62037857
>Casting void pointers
>Good C
>>
>>62037823
>compiling C with a C++ compiler
>>
>>62037878
>not using char*
>>
>>62037885
>using char*
>>
>>62037898
>not using char*
>>
>>62037905
>not using void*
>>
>>62037916
>using type-unsafe behavior
>>
>>62037923
>using behavior
>>
>>62037923
>muh type safety
>>
If you can't understand this, you shouldn't be posting here.

PROCEDURE SinI(x: LONGREAL) : LONGREAL;
VAR
a, c, z, tmp: LONGREAL;
BEGIN
IF ~Finite(x) THEN (* sin(NaN) and sin(INF) must be NaN *)
RETURN x - x
END;
x := Rem(x, PI2); (* reduce x into [-PI,PI] *)
a := CopySign(x, 1.0);
IF a >= PIo4 THEN
IF a >= PI3o4 THEN (* ... in [3PI/4,PI] *)
a := PI - a;
x := CopySign(a, x);
ELSE (* ... in [PI/4,3PI/4] *)
a := PIo2 - a; (* rtn. sign(x)*C(PI/2-|x|) *)
z := a * a;
c := CosC(z);
z := z * half;
IF z >= thresh THEN
a := half - ((z - half) - c);
ELSE
a := 1.0 - (z - c);
END;
RETURN CopySign(a, x)
END;
END;

IF a < small THEN (* return S(x) *)
tmp := big + a;
RETURN x
END;

RETURN x + x * SinS(x * x)
END SinI;
>>
>>62037934
take your shitty meme language elsewhere
>>
>>62037946
Functional languages are meme languages, anon. Not Oberon.
>>
>>62037961
>muh simplicity
>>
>>62037934
>end
>:=
just leave and stop embarrasing yourself
>>
Give me one (1) good reason not to cast void pointers.
>>
>>62037848

Then change clang to clang++
>>
>>62037931
>not inlining assembly code for unsafe operations
>>
Why are drivers and the Linux kernel still written in C? Seems like C++ is just as fast, and often takes less effort to implement the same things when compared to C. Also, C++ is supposed to supersede C so all the legacy code should be compatible with C++, no?
>>
>>62037990
simplicity and to annoy faggots who compile C with a C++ compiler
>>
>>62037990
it's literally a hack
>>
>>62037916
void *meme;
if (comfy << (finished & bankrupt) == *botnet)
meme = &botnet;
>>
>>62037976
Spotted the brainlet.
>>
>>62037823
Dumb akariposter
>>
>>62038005
>using non-portable assembly
>>
I have no ideas and i must program
>>
>>62038035
Create a OS Kernel with support for x86 and ARM (32 and 64)
>>
>>62038006
C++ is too big and people will write code in a way that is inappropriate for a kernel or drivers. Once you subset C++ to what is appropriate, you're mostly left with C.
Also there's plenty of C that won't compile as C++. You can usually write C++ that is extremely similar to equivalent C though.
>>
oops i posted this in the old thread

what is the proper way to have variables shared between threads when only one thread writes and the other reads (no real risks) in C++?
Do I just declare global variables?
>>
>>62037885
I'm confused. Are you suggesting we go into malloc's code and change it all from void* to char*?
>>
>>62038006
C++ is a retarded clusterfuck and almost all of the features it adds are utterly inappropriate for the domain that C is usually used in.
>>
>>62038057
char* is the original generic pointer, yes.
>>
>>62038006
>legacy code should be compatible with C++, no?
No.
C++ is not a superset of C.
>>
>>62038068
>original
>better
>>
>>62038068
https://www.kernel.org/doc/htmldocs/kernel-api/API-kmalloc-array.html
>>
Thoughts?

PROCEDURE Truncate(x: LONGREAL) : LONGREAL;
VAR
ieee754: IEEE754;
BEGIN
IEEE754Real2ExpMan(x, ieee754);
ieee754.mantissa1 :=
SYS.VAL(INTEGER,
SYS.VAL(SET, ieee754.mantissa1) * SYS.VAL(SET, 0F8000000H));
IEEE754ExpMan2Real(ieee754, x);
RETURN x
END Truncate;

BEGIN (* LnI *)
(* catch special cases *)
IF x <= 0.0 THEN
IF x = 0.0 THEN
RETURN - hugeVal (* log(0) = -Inf *)
ELSE
RETURN nan (* log(neg) = NaN *)
END;
ELSIF ~Finite(x) THEN
RETURN x + x (* x = NaN, Inf *)
END;

(* Argument reduction: 1 <= g < 2; x/2^m = g; *)
(* y = F*(1 + f/F) for |f| <= 2^-8 *)
m := Trunc(LogB(x));
g := LdExp(x, -m);
IF m = - 1022 THEN
j := Trunc(LogB(g)); INC(m, j);
g := LdExp(g, -j);
END;
j := Trunc(n*(g-1.0) + 0.5);
F := (1.0 / n) * j + 1.0; (* F*128 is an integer in [128, 512] *)
f := g - F;

(* Approximate expansion for log(1+f/F) ~= u + q *)
g := 1.0 / (2.0 * F + f);
u := 2.0 * f * g;
v := u * u;
q := u * v * (A1 + v*(A2 + v*(A3 + v*A4)));

IF (m # 0) OR (j # 0) THEN
(* case 1: u1 = u rounded to 2^-43 absolute. Since u < 2^-8,
u1 has at most 35 bits, and F*u1 is exact,
as F has < 8 bits.
It also adds exactly to |m*log2_hi + log_F_head[j] | < 750
*)
u1 := u + 513.0; u1 := u1 - 513.0;
ELSE
(* case 2: |1-x| < 1/256. The m- and j- dependent terms are zero;
u1 = u to 24 bits.
*)
u1 := u; u1 := Truncate(u1);
END;
u2 := (2.0*(f - F*u1) - u1*f) * g;

u1 := u1 + m * logFHead[n] + logFHead[j]; (* exact *)
u2 := (u2 + logFTail[j]) + q; (* tiny *)
u2 := u2 + logFTail[n] * m;
RETURN u1 + u2
END LnI;
>>
>>62038049
I'm (just) a shitty .NET developer microshill, this is way outside my league.

thank you, though.
>>
>>62038006
Because C is closer to assembly than C++. Also generally better at using the least amount of memory.
>>
>>62038006

>Why are drivers and the Linux kernel still written in C?
For drivers: compatibility with the kernel's API/ABI
For the kernel: not having to rewrite everything in C++. Also, Linus Torvalds hates the shit out of C++ programmers.

>so all the legacy code should be compatible with C++, no?
This is absolutely false. The following is invalid C++:
char *foo = malloc(10);


Extrapolate from there.
>>
>>62038006
Linus doesn't like C++, git is also written in C although it's a userspace app.
>>
>>62038137
>app
>>
What about now?
#include <stdio.h>

int
main()
{
int b, c;
char a, d;


printf("Does your \"gf\" have a penis? Y/N:");
scanf(" %c", &a);

if (a == 'Y')
{
printf("Is it a femenine penis? Y/N:");
scanf(" %c", &c);
if (c == 'Y')
printf("Nice!\n");
else
printf("Gay as fuck bro\n");
}
else
{
printf("Did she have a penis before? Y/N:");
scanf(" %c", &d);
if (d == 'Y')
printf("Disgusting.\n");
else
printf("3D women lmao\n");
}

return 0;
}
>>
never done webdev

before i get too far, is github pages enough to host a decent looking resume webpage? just for a uni student to apply for internships.

https://pages.github.com/
>>
>>62037860
It's not like I ever wanted.
Replace with C++, it would be more accurate.
>>
>>62038195
>not using getc instead of scanf
>not handling invalid answers
>not handling lowercase
>>
>>62037990
You don't have to waste the time typing the cast out every single time?
>>
>>62038227
>>62038011
>>62038007
still waiting
>>
File: 1492768104351.jpg (228KB, 772x525px) Image search: [Google]
1492768104351.jpg
228KB, 772x525px
>>62038219
>>
File: java.jpg (155KB, 724x810px) Image search: [Google]
java.jpg
155KB, 724x810px
Why is Java so smug?
>>
>>62038259
>muh C++ compatibility
nice bloat faggot
>>
>>62038265
Because the people who use it actually have jobs.
>inb4 pajeet meme
>>
>>62038265
it's underage and two-dimensional
>>
>>62038265
POO
>>
I'm working on a chan browser, and I'm learning the joys of the Android ecosystem. Apparently it crashes on Samsung Chrome Books, but every other device is fine.

Why can't Android just run the same on all devices? :(
>>
If your favorite language isn't compiled to native code, you're a shitskin.
>inb4 paJIT butthurt
>>
>>62038195
It's better to use a state machine, enums and switch case statements for such things.
>>
What is the most unnecessarily bloated programming language in existence?
>>
>>62038332
inb4 C++
>>
>>62038314
>Why can't Android just run the same on all devices? :(
Works on my machine. Code monkey spotted.
>>
>>62038332
No idea. Probably Java?
>>
>>62038332
Haskell and C written by /dpt/ posters.
>>
>>62038332
SystemC?
>>
>>62038332
X86 assembly. Assembly is supposed to be simple, not "extended".
>>
>>62038356
Java's pretty simple though. The only major changes have been Java 5 and Java 8, and those combined didn't add as many features as e.g. C++11.
>>
>>62038332
OCaml.
>>
>>62038225
>>not handling lowercase
I've got his back :^)
((a & ~(1<<7)) == 'Y')
>>
>>62038391
>not handling unicode
>>
>>62038391
wtf
explain this code pls i'm stupid
>>
Is C primary used to program hardware?
>>
>>62038448
bitwise operators on ASCII characters, there're also redundant parentheses around the bitwise and
https://graphics.stanford.edu/~seander/bithacks.html
>>
>>62038262
Perfect
>>
>>62038450
If you mean low level, that would be assembly.
If you mean high level, that would be some scripting language.
I'm not sure if the grey area in the middle that does use C is big enough to have majority in the overall sum.
>>
>>62038405
Anon's code doesn't handle Unicode either.
>>
>>62038314
Was thinking about making one for ios, might add cashing and shit like that cause I like to browse on a train. Is the API good? Is it publicly available and documented?
>>
How do you deal with containers of base class pointers to store derived objects? It is good practice? I'm trying to use in a little project of mine, just to explore C++, and I don't know how to do overloading with the pointed object.

If an object A, derived from B, is accessed by a pointer to B, and I pass that object to a function, the compiler can only call the function that accepts B as an argument, right? The only thing I can think of is doing casts, but that sounds like terrible code. Is there a way to make C++ make a runtime type checking and call the right function? My program design is broken?
>>
>>62038715
Google "Polymorfism"
>>
What's more aesthetic for platform-dependent drivers in an OS directory structure?
Linux uses the latter

/platform/lpc11xx/i2c.c VS /drivers/i2c/lpc11xx-i2c.c

Other drivers are in folders like /drivers/net/enc28j60.c
>>
>>62038715
See https://sourcemaking.com/design_patterns/visitor/cpp/3
>>
>>62038715
>How do you deal with containers of base class pointers to store derived objects? It is good practice?
Yep it's pretty standard.

>If an object A, derived from B, is accessed by a pointer to B, and I pass that object to a function, the compiler can only call the function that accepts B as an argument, right? The only thing I can think of is doing casts, but that sounds like terrible code. Is there a way to make C++ make a runtime type checking and call the right function?
You're looking for virtual functions.
class Base 
{
public:
virtual void sayHello() { std::cout << "Hello from Base"; };
};

class Derived : Base
{
public:
void sayHello() override { std::cout << "Hello from Derived"; };
}

int main(int argc, char **argv)
{
Base *ptr = new Derived;
ptr->sayHello(); // prints "Hello from Derived"
}
>>
why does it feel like 95% of webdev is just stealing other peoples code

:thinking:
>>
>>62038819
It's all about getting shit done so why reinvent the wheel when you can import everything and glue it together.
>>
File: 1481354.png (74KB, 400x400px) Image search: [Google]
1481354.png
74KB, 400x400px
stoopid losers with your dumb "hello world!" languages

learn some real shit
>>
>>62038521
It's pretty straightforward. It's just JSON. The "documentation" is just one page, and it's not supported as in if you run into issues it's up to you to solve them
>>
>>62038788
thanks
>>
>>62038862
t. i will never get a job
>>
reminder that the most employable languages are

>sql
>java
>javascript
>python
>c#
>>
missed new thread

>>62036441
>the code produced should be almost all the same
not quite; the rather important difference is that in the template version, n is a constant expression, which allows for potentially many implicit and explicit optimizations depending on the nature of the doThis function

>so duplicating it per template instance is completely redundant
each instantiation is specialized for a given constant value of n; constant expressions involving n which can be computed at compile time (potentially any pure C++ expression/function/lambda on any statically/predictably-sized values/types at this point thanks to constexpr) are unrolled/inlined until the point where they are used in a non-constant expression, then those values (also visible to compiler optimizations) are stored directly in the binary, intermediate values are discarded (maybe cached by the compiler but not added to the assembly), and the assembly for the instantiation ends up being what you'd get (after the other usual optimizations) for just the non-constant expressions given the cached constants and the non-constant value(s). or it would be, except it's a template instantiation so it's probably inlined. it may not always be a big difference (though even trivial cases can benefit, like if the compiler unrolls a loop because it's obviously deterministic due to a constant boundary), but in more complex cases it can eliminate potentially many runtime operations

>>62036528
>The question is, will the compiler be smart enough to not emit a shitton of repeated code?
yes, only one (probably inlined, especially if constexpr) instantiation is generated for each unique value of n used. and in fact, similarly to intermediate/unused constexpr values, constexpr functions and instantiations used only in constant expressions and not at runtime are discarded

>Unless the function gets inlined, I don't trust it not to
template functions are inline by default except in the case of explicit instantiations
>>
>>62038897
Have you actually looked at job openings for Elixir?

Probably not
>>
>>62038928
>Have you actually looked at job openings for Elixir?
Pretty hard when there are none.
>>
>>62038923
Is the performance advantage for loop unrolling going to be worth the icache misses you're going to get from bloating the code size from each instantiation with a different array size?
>>
>>62038912
two of those languages are untyped trash
>python
>javascript
two of those languages are corporate owned:
>c#
>java
the remaining language is the perfect representation of set theory, the ultimate fusion of mathematics, computer science and economics
>>
>>62038944
hmm?

http://jobs.elixirdose.com/
>>
Why is Java the worst programming language?
>>
>>62039003
Java is pure. Java is love.
>>
>>62039003
Because it's designed for idiots.
>>
>>62039003
It's the best
>fast
>works with every computer
>object oriented
>exceptions
What do you want more?
>>
>>62039023
>What do you want more?
compiled, garbage collected, well tooled
on wait java has all of those
goddamn I love java.
>>
>people wasting time learning all these shit languages

Just fucking learn, no, master C and C++ and you'll bank big.
You can then learn all the meme languages in your free time
>>
>>62038521
they'll never let you on the store, unfortunately
>>
>>62039023
>>fast
>>works on any computer
JIT only works on specific hardware and without it Java is slower than python
>>
>>62038715
Use virtual functions to get dynamic dispatch.
You should also read up on public versus private inheritance in C++. A `class` will privately inherit by default
Ex1:
#include <array>
#include <iostream>

class BB {
public:
int fn1 (void) { return 1; };
virtual int fn2 (void) { return 2; }
};
class CC : BB { int fn2 (void) override { return 3; } };
class DD : public BB { int fn2 (void) override { return 4; } };

int main (void) {
CC cc;
// cc.fn1 (); // this will fail to compile since BB::fn1 isn't visible due to privately inheriting.
DD dd;
dd.fn1 (); // will compile fine because DD inherited BB publicly.
// we need to cast the CC pointer to a BB pointer because BB isn't visible from a CC view. the "right" way to do this would be to have CC have a method that returns a BB pointer to itself.
std::array<BB*, 2> bb { (BB*)&cc, &dd };
for (auto& elem : bb) {
// we can call fn1 fine from these since BB::fn1 is visible from a BB view.
std::cout << elem->fn1 () << " | " << elem->fn2 () << std::endl;
}
return 0;
}
>>
>>62039088
also friend classes for when its too late and you've already fucked up and can't change everything :)
>>
File: 1501711788800.jpg (18KB, 480x360px) Image search: [Google]
1501711788800.jpg
18KB, 480x360px
its totally possible to write c code that will compile in c++ without sacrificing anything, if your code doesnt compile you are a shitter not c programmer
>>
File: 1503393254513.jpg (199KB, 1920x1080px) Image search: [Google]
1503393254513.jpg
199KB, 1920x1080px
teach me how to sepples pls
>>
>>62038391

Couldn't you just have written (a & 128) instead?
>>
>>62039130
C++ is not a superset of C
>>
>>62039144
Slap shit together. Whenever you see something new, play with it until you figure out how it works. It's an endless maze, perfect for a NEET with nothing better to do.
>>
>>62039158
and?
>>
>>62039130
There's lots of features in C that don't work at all in C++ that i refuse to give up.
Stuff like variable initializer elements and anonymous unions.
>>
>>62039158
Correct, but there is close to nothing that can be done in C that cannot be done in C++.
>>
>>62039170
And I like calling my variables "class".
>>
>>62039178
>t. OOPfag
>>
>>62039182
clearly not part of the kool kids klub, i.e. Java with their klass and klazz everywhere.
>>
>>62039182
then you are a shitter

>>62039170
these are in c++
>>
C++tards GTFO nobody wants you here
>>
>>62038792
I've always hated how everyone demonstrates polymorphism like this in C++, you'd never even write something like that.

struct Base
{
virtual void sayHello() { std::cout << "Base"; }
};

struct Derived : Base
{
void sayHello() override { std::cout << "Derived"; }
};

void call(Base& object) { object.sayHello(); }

int main() {
Base base;
Derived derived;
call(base); // prints Base
call(derived); // prints Derived
}

This is what the poster was looking for, too
>>
>>62038715
As the other anons mentioned, virtual functions are the way to go. If for some reason, however, you cannot know which functions you will call in your derived class, then you can use static_cast and dynamic_cast. Like so:

#include <cstdio>
#include <memory>
#include <vector>

struct A {
A(int val) : val(val) { printf("create A%d\n", val); }
virtual ~A() { printf("delete A%d\n", val); }
int val;
};

struct B : A {
B(int b = 0) : A(b) {}
void foo() { printf("foo %d\n", val); }
};

void bar(std::unique_ptr<A>& ptr_ref)
{
printf("bar %d\n", ptr_ref->val);
}

int main()
{
std::vector<std::unique_ptr<A>> v;
v.emplace_back(std::make_unique<B>(1));
v.emplace_back(std::make_unique<B>(2));

for (auto& e : v) {
dynamic_cast<B*>(e.get())->foo();
// or use static_cast for lesser safety
bar(e);
}
printf("finish\n");
return 0;
}
>>
>>62037763
girl on the right is cuter though
>>
>>62039249
>>62038792
Never, ever, ever, ever use inheritance.
>>
In C, how to generate a random array of int values where each number occurs exactly once? For example, an array of size 5 would contain values 0..4.

[4, 1, 3, 0, 2]
>>
>>62039392
Why?
>>
>>62039420
http://www.yegor256.com/2016/09/13/inheritance-is-procedural.html
>>
>>62039420
Too conventional.
>>
>>62039419
You mean a random permutation.
>>
>>62039419
Make an array with values from 0 to 4 and then permute it.
>>
>>62039419
generate a new number, scan through all your previous numbers to see if it hasn't occured yet.
If your range is small enough, it's possible to do this efficiently with bitwise vectors.
>>
File: comfy.png (2MB, 802x802px) Image search: [Google]
comfy.png
2MB, 802x802px
what classes are you taking this semester? i'm taking a computer architecture elective (no programming, pen & paper homework), a required databases class (programming), and a high performance computing class (parallel programming with C). just 9 credit hours, and then my self directed research brings me up to full time. is your semester comfy like mine?
>>62039419
do your own homework cuck
>>
>>62039419
Fisher–Yates
>>
>>62039419
Just upgrade to C++.
std::vector<int> numbers{size};
std::iota(numbers.begin(), numbers.end(), 0);
std::shuffle(numbers.begin(), numbers.end(), std::mt19937{std::random_device{}()});
>>
>>62039419
See chapter 2 section 4 of Sheldon Ross' Probability Models for Computer Science.
>>
 impl Gf for Me 
>>
Is there even a single one of you who can write adept code in Oberon?
>>
[1..]
>>
>>62039419
Output
[0, 1, 2, 3, 4]
, you can't prove it's not random.
>>
>>62039509
>you can't prove it's not random
lrn2chi-squared testing, faggot
>>
>>62039528
>chi-squared testing
Not a proof.
>>
>>62039509
what class allows you to just submit executables?
>>
>>62039430
Yegor is love. Yegor is life.
>>
>>62038102
I'm math illiterate and I'm not a good programmer, but that seems overly complicated for a truncate function.
>>
anyone hiring for a job i really need work
>>
>>62039546
>I've never seen a pumpkin turn into a coach
>"durr that doesn't mean pumpkins can't turn into coaches, it only means they don't usually do! hurrr"
You're clinically retarded.
>>
>>62039609
>expecting non-retards to be on 4chink
>>
>>62039609
That's literally correct though.
>>
Alright windows if fucking retarded for programming in C. I want my emacs and gcc back. I already have VMware installed from back when I was playing PSO2, what am I looking to install: unix, linux? I used to just ssh into the campus computers so I have no idea what I'm looking for.
>>
>>62038195
Problems:

1. b isn't used.
2. c, a and d weren't initialized
3. c is an int
4. c and d are in the outermost scope

Comments:

1. isn't really a problem

2. if scanf fail the contents of c, a and d are undefined

3. scanf will change only one byte of c. if you didn't initialize it then the contents are garbage so if the user answers 'Y' to the second question the value of c will be within the range 89, 4294967129 if int is 32 bit.

4. c and d being in the outermost scope clutters the namespace and difficults reading if the function gets big, they should be within the first if/else pair (the ones that checks wether the gf has a dick).
>>
>>62039732
You can install GNU Emacs on WIndows and use M$ C compiler.
>>
>>62039747
He can also use mingw. The lead dev for the C++ STL at Microsoft even provides a pretty up-to-date portable distribution with a bunch of libraries pre-compiled included. It even includes gdb.

(or use WSL, or msys)
>>
>>62039732
Just embrace the MSVS, anon. Community edition is free.
>>
>>62039088
>dynamic dispatch
C++ doesn't have it, at least not in its entirety, but you can emulate with the Visitor pattern.
>>
>>62039776
In any case, it's very simple.
>>
>>62039130
yes, but the problem is that to comply to c++ rules you in turn make the c code less safe when you have to compile it as c, unless you write a bunch of macros that behave differently from c and c++ builds.
>>
>>62039776
tfw I mailed him a stupid question the other day without realizing it's him
felt pretty stupid
>>
>>62039732
too late, you're one of us now
>>
>>62039826
but you still got your answer, didn't you? :)
the guy is extremely active on leddit. it seems he's one of the few trying to make MSVS not total trash.
>>
>>62039747
>>62039792
The compiler is what's shit. It can't into C99. I started googling how to get gcc on win7 and that lead me to believe it'd be easier to just VM whatever I was probably using on campus.

>>62039776
Assuming I got whatever this is working, can I expect the ease of use to be comparable to just typing make into the terminal after saving the file? Or am I better off just figuring out how to install unix/linux?
>>
>>62039732
>Alright windows if fucking retarded for programming in C.
windows ides often bundle everythign together. what issues are you having? try these:

QtCreator (you can install it and Gcc with the QtSDK installer)
Visual Studio (comes with "cl" if you enable c/c++ support in the installer and now you can even enable clang support in the installer IIRC)
Code::Blocks (they used to have a code blocks + gcc installer/zip file)
MSYS2's QtCreator (you can install both gcc and clang from the command line, plus you get a bunch of linux goodies)
>>
>>62039890
I use MSYS2 for devving on windows. I can install gcc, vim, emacs and even qtCreator too. All libraries are one pacman -S away
>>
>>62039844
yes, he politely answered and very quickly while at that, I felt stupid nonetheless because right after I sent a mail I found an issue in the tracker where he explicitly said he won't address that due to various reasons
>>
>>62039890
>It can't into C99.
Useless. C89 is the only C.
>>
>>62039991
Fuck off macroshill, nobody cares if you're too lazy to implement C99 and above
>>
>>62039991
I want to declare my erroneous counter variables inside the for loop initialize.
>>
>>62039797
Virtual functions are dynamic dispatch. You're thinking of multimethods.
>>
>>62038198
Yeah it's what I use
>>
if err != nil {
return nil, err
}
>>
>>62040104
this returns just err, right?
>>
>>62040135
this happens in go when you return two things: the object, and possibly an error, so its like nil, err when theres an error, or thing, nil when there is no error
>>
>>62039588
Show me your Oberon.
>>
>>62040173
why not use a variant type
>>
>>62040195
because
>go
>>
>>62040195
type system too retarded
>>
>>62040229
sad
this seems like the perfect situation for a tagged union of value/error
>>
reminder that you can did this in idris and it work and that's why idris is them wrist language ever made
data x: Nat
>>
monads
>>
File: why is this code wrong.png (93KB, 1054x495px) Image search: [Google]
why is this code wrong.png
93KB, 1054x495px
why is this algorithm wrong anons? i want to generate a random number between (-range, range)

but its very rare to get x > 0, its almost 50/50 to get 0 or x < 0 which is weird desusenpai
>>
File: 1494896495363.jpg (165KB, 1360x1053px) Image search: [Google]
1494896495363.jpg
165KB, 1360x1053px
on and off touching up my image board software, wrote it from scratch a year or two ago but it works nicely now.
theden.xyz
>>
>>62040267
they went all out with multiple returns instead, even though you can achieve exactly the same thing with tuples and destructuring (also variant types like you said)
>>
can someone give me a link to a TLDR resource on compilers? i have limited time now with classes
>>
>>62040310
rand() is garbage
>>
>>62040267
exceptions are better
the problem with tagged unions of value / error is that you have to manually unwind the stack until you get to a scope at which the error is recoverable
with exceptions you just specify the recovery code and errors automatically unwind the stack until they find it
of course both of these approaches are inferior to the ideal which is to check if operations are possible before starting to do them
>>
Write a C++ program that can save and load cyclic data structures, and I'll send you a referral for a nice position.
>>
Am developing a C Win32 client.

Need to manage all kinds of signals/events, both keyboard ones and server disconnections or stuff like that.

Can't find a decent MSDN or anything that explains how to properly manage signals in Windows, can you guys help me find some useful documentation about it?
>>
>>62040378
>save and load cyclic data structures
you mean a cyclical array? sounds about as difficult as making one that can save and load non-cyclical data structures. there's no major difference in initialization, only access
>>
is it possible to work 12 hours a day? or 8 during the week and 10 hour days in the weekend?
>>
>>62040376
You have to handle errors somehow. Either you make it an invisible alternate execution path with an exception or you encode it in the return type. Personally, returning a variant between the result value and an error seems to be the clearest way to encode what effect executing a function will have.
>>
>>62040463
agree, and additionally, you know what the function does just by looking at the signature
>>
>>62040376
unfortunately, operations might suddenly become impossible after you check that they are possible
>>
>>62040427
Yes,but after 2 weeks you productivity goes to shit and could get burnout syndrome.
>>
>>62040488
That's what I enjoy about a powerful type system.
>>
Anyone here able to produce an interface to a Tcl/Tk interpreter?
>>
>>62040378
Sounds pretty trivial. Where's the catch? I'd write but I'm in bed already.
>>
>>62040531
i don't think there is a catch, i think he's just retarded and it's a homework problem. it'd be as simple as writing a line to a file for each entry in the datastructure, vs doing an insertion for each entry in a file for reading
>>
>>62040496
i already get that with 7 hours a day fuck me kek
>>
>>62040378
A matrix can represent cyclical data structures. Next question.
>>
>>62040582
If it were homework I'd say so.
All I see is kids like you talk the talk, yet no results in sight. Come on, let's see how you write it and I'll be the judge on whether or not it's up to standard.
>>
>>62040517
Nobody?
>>
File: 1481312879672.png (549KB, 1920x1080px) Image search: [Google]
1481312879672.png
549KB, 1920x1080px
>>62038035
Here you go
>>
go py 2 first or 3 instead and back to 2 if needed?
>>
>>62040699
3 first, 2 is deprecated
both are v similar tho
>>
>>62039370
Yeah stock photo edits should go for accuracy above all else.
>>
File: dd.png (140KB, 347x495px) Image search: [Google]
dd.png
140KB, 347x495px
>>62040680
Free Divine Divinity gift on Steam for anyone who writes 77 from scratch.
>>
>refactoring old code
>see something that makes no sense
>look at the comment by it
>//lol good luck nerd
Anyone else write comments like this?
>>
>>62040699
>>62040715
I'm surprised they broke backwards compatibility. A language like C++ could benefit so much from doing that yet they don't.

I applaud them for actually taking these measures where they saw them fit but isn't it basically just admitting that python code is pretty much worthless?
>>
>>62040783
correct, python is trash
im maintaining a python project now and the lack of typing is simply awful
>>
>>62038225
>>62038328
>>62039744
This is the best I can do, really. I'm only 4 chapters in. But thank you, I know more about if now than I did before
#include <stdio.h>

int
main()
{
char ans, ans2;


printf("Does your \"gf\" have a penis? Y/N:");
scanf(" %c", &ans);

if (ans == 'Y')
printf("Is it a femenine penis? Y/N:");
else if (ans = 'N')
printf("Did she have a penis before? Y/N:");

scanf(" %c", &ans2);

if (ans2 == 'Y' && ans == 'Y')
printf("Nice!\n");
else if (ans2 == 'N' && ans == 'Y')
printf("Gay as fuck bro.\n");

if (ans2 == 'N' && ans == 'N')
printf("3D women lmao\n");
else if (ans2 == 'Y' && ans == 'N')
printf("That's gross\n");

return 0;
}
>>
>>62040772
I write lots of code that's just primed for deletion. I never leave code that's in use and incomprehensible.

I also annotate issues I see with code.
Like #slow #refactor #security

I'd like to see people do that more. I hate reading code and thinking 'does the author know this aspect of this peace of code?'. Because not everything is worth bringing up.
>>
>>62040828
>taking comments seriously
lol nerd
>>
>>62040820
I just noticed that I could have written
 else if (ans2 == 'N' && ans == 'N')
>>
File: inv.png (321KB, 540x573px) Image search: [Google]
inv.png
321KB, 540x573px
>>62040680
The whole inventory for anyone who can write 98.
>>
>>62040680
A lot of these seem really nebulous, or inconsistent in difficulty. For example, it's not implied whether using external libraries is cheating in a given scenario.
>>
>>62038862
What language is that?
>>
>>62040922
98
>>
>>62040922
>>>/v/
>>
>>62040964
elixir
>>
>>62040964
hipsters trying to turn a nice, but quirky godsend to distributed computing into webscale shit with soft syntax to help with their weak fingers.
(elixir = ruby syntax on erlang's beam VM)

https://www.youtube.com/watch?v=rRbY3TMUcgQ related
>>
>>62037934
What version of my waifu Pascal is this?
>>
>>62039049
C and C++ are the most valuable when it comes to getting a job? Newfag here
>>
@62038133
>Also, Linus Torvalds hates the shit out of C++ programmers
"I once read a pasta and didn't bother to get more informed since" - the post. Expected of a tripqueer though.
>>
>>62041054

Honest question: why would anybody care about what Linus Torvalds think about C++? I know who he is and what he has done and without any doubt he is a very experienced programmer but why should a regular software developer care about his opinion when C++ allows them to write programs easier?
>>
>>62041085
Ironically, years after that statement he started to use C++ and Qt to make software for a business. He hasn't spoken much about how bad C++ was then, only how shitty Gtk was with C.
(subsurface is the software. he gave a talk on it and why they switched from c/gtk to c++/qt)
>>
Which language has the best tools to make a pretty gui ?
>>
>>62041228
visual basic
>>
>>62041228
don't do >>62041277, it's for noobs
do visual advanced
>>
>>62041277
>>62041298
topkek
>>
>>62041228
Gambas
>>
Hey /dpt/, got a question for you all.

If you were on your first day starting a job developing a program (for which you haven't seen the code) and you got ten minutes to ask the previous developer questions about the program before he departs, what would you ask? If that's language dependent then let's say C#
>>
>>62041228
Tcl/Tk
>>
>>62041228
Object Pascal.
Install Lazarus.
>>
>>62041298
Invisible Basic is the patrician choice
>>
>>62041323
Nothing, I'd ask for a detailed guide from the guy I'm replacing as a prerequisite to my employment contract.
>>
>>62041341
>not going the extra mile by using Invisible Advanced
>>
I've run into a situation where I have big blocks of data that need to be shifted around / rotated a lot; and I feel a way to optimize this would be to have a list of pointers that shift around respective to the data, but have the data itself stay where it is, with the exception of replacing the oldest block of data with the newest one.

Is such a thing a good idea? I've tried to sketch it out on paper but I'm having trouble keeping track of everything.

Say there's an array of n pointers to different instances of a data structure. The pointer at the end of the array points to the data that was accessed the earliest, while the first pointer points to the data that was accessed most recently. If new data is accessed, the pointers would rotate, with pointer 3 for example now pointing to the 4th recently accessed data, and the oldest pointer now being brought to the front of the list, with its old data being overwritten by new data.

But if recently accessed data is accessed again, since it's already cached, its pointer should just be brought to the front of the list, and nothing else needs to happen.

Could Would this work, or would it be better to just avoid the headache / high vulnerability for bugs/difficult-to-pinpoint logic errors and perform the big shifts of memory? I'm targeting this towards a system with limited resources, so optimizations are important.
>>
File: qt4-qws-1.png (85KB, 1024x768px) Image search: [Google]
qt4-qws-1.png
85KB, 1024x768px
>>62041228
Pic related my man
>>
>>62041355
Nigga, just learn Translucent Fluent already!
>>
>>62041228
C++ QML
HTML
>>
>>62038959
loop unrolling was just an example (and not at all guaranteed), my main point was the rest of it. and actually it seems like the real culprit for binary bloat/icache misses is overinlining. but consider:
- instantiations which do constexpr computations and/or facilitate compiler optimizations on template arguments remove some runtime computations altogether (compared to non-template) and are thus likelier to inline well
- inlined instantiations which are well-suited for inlining won't bloat the binary any more than the alternative due to inlining at least as well and because their definitions won't appear in the binary, and this scenario will occur in more cases due to first point
- uninlined instantiations which are not well-suited for inlining would still tend to be individually smaller than non-template alternative (which also indirects/in binary), with often smaller call sites due to passing less runtime data. in this case number of instantiations, among other things, would indeed affect whether or not template approach yields smaller binary
so the most important thing is to avoid overinlining, which will yield bigger binaries in either case. but in very many cases (especially any that make use of constexpr computations on template arguments; a common case), a template approach is more likely to be overall more efficient. which kind of makes sense because it moves some data and potentially computations onto the compiler
>>
>>62040820
amateur
#include <stdio.h>
#define yes (ans == 'y' || ans == 'Y')
#define no (ans == 'n' || ans == 'N')

int main() {
char ans;
printf("Does your \"Gf\" have a penis? ");
ans = getchar();
while(getchar() != '\n') ;
if (yes) {
printf("Is it a feminine penis? ");
ans = getchar();
if (yes)
puts("Nice!");
else if(no)
puts("Gay as fuck bro");
else
goto wrong;
} else if (no) {
printf("Did she have a penis before? ");
ans = getchar();
if(yes)
puts("That's gross");
else if (no)
puts("3D women lmao");
else
goto wrong;
} else {
goto wrong;
}
return 0;
wrong:
puts("Install Gentoo you retard");
return 1;
}
>>
>>62041499
also, profile before making assumptions..
>>
File: sad_meme_frog.jpg (20KB, 500x484px) Image search: [Google]
sad_meme_frog.jpg
20KB, 500x484px
>>62041298
>you'll never get past Visual Intermediate
>>
>>62041041
Oberon-7
>>
You know what this does, right /dpt/?

PROCEDURE CosI(x: LONGREAL) : LONGREAL;
VAR
a, c, z, s: LONGREAL;
tmp: LONGREAL;
BEGIN
s := 1.0;
IF ~Finite(x) THEN (* cos(NaN) and cos(INF) must be NaN *)
RETURN x - x
END;
x := Rem(x, PI2); (* reduce x into [-PI,PI] *)
a := CopySign(x, 1.0);
IF a >= PIo4 THEN
IF a >= PI3o4 THEN (* ... in [3PI/4,PI] *)
a := PI - a;
s := - 1.0;
ELSE (* ... in [PI/4,3PI/4] *)
a := PIo2 - a;
RETURN a + a * SinS(a * a); (* rtn. S(PI/2-|x|) *)
END;
END;
IF a < small THEN
tmp := big + a;
RETURN s (* rtn. s*C(a) *)
END;
z := a * a;
c := CosC(z);
z := z * half;
IF z >= thresh THEN
a := half - ((z - half) - c);
ELSE
a := 1.0 - (z - c);
END;
RETURN CopySign(a, s)
END CosI;
>>
>>62041617
DON'T RUN IT, IT'S NERVE GAS!!!
>>
>>62041526
while(getchar() != '\n') ;

I'm guessing this brakes input to only read first character?
>>
>>62041617
PROCEDURE DoIt() : LONGREAL;
VAR
tmp: LONGREAL;
BEGIN
(* begin argument reduction *)
IF t < 2.4375 THEN
(* truncate 4(t+1/16) to integer for branching *)
k := Trunc(4.0 * (t + 0.0625));
CASE k OF
| 0, 1: (* t is in [0, 7/16] *)
IF t < small THEN
tmp := big + small; (* raise inexact flag *)
IF signx > 0.0 THEN
RETURN CopySign(t, signy)
ELSE
RETURN CopySign(PI - t, signy)
END;
END;
hi := 0.0; lo := 0.0;
| 2: (* t is in [7/16, 11/16] *)
hi := athfhi; lo := athflo;
z := x + x;
t := ((y + y) - x) / (z + y);
| 3, 4: (* t is in [11/16, 19/16] *)
hi := PIo4; lo := 0.0;
t := (y - x) / (x + y);
ELSE (* t is in [19/16, 39/16] *)
hi := at1fhi; lo := at1flo;
z := y - x; y := y + y + y; t := x + x;
t := ((z + z) - x) / (t + y);
END;
ELSE
hi := PIo2; lo := 0.0;

IF t <= big THEN
(* t is in [2.4375, big] *)
t := - x / y;
ELSE
(* t is in [big, INF] *)
tmp := big + small; (* raise inexact flag *)
t := 0.0;
END;
END;

(* compute atan(t) for t in [-.4375, .4375] *)
z := t * t;
z := t*(z*(a1+z*(a2+z*(a3+z*(a4+z*(a5+z*(a6+z*(a7+z*(a8+
z*(a9+z*(a10+z*a11)))))))))));
z := lo - z; z := z + t; z := z + hi;

IF signx > 0.0 THEN
RETURN CopySign(z, signy)
ELSE
RETURN CopySign(PI - z, signy)
END;
END DoIt;
>>
noob here
is it possible to write a program that when run deletes files on pc etc?
>>
>>62041617
>>62041658
What the fuck is this shit? looks way too complicated.
>>
>>62041651
It skips to the next line
>>
>>62038006
https://lwn.net/Articles/249460/
>>
>>62038195
>>62040820
>
int
main()
{

stop
>>
>>62041555
well, you'd have to profile because you may or may not be overinlining or overinstantiating, yeah. but this should serve as an accurate indicator of the relative likelihoods of the individual scenarios. my point was just that, given that template arguments/constexpr migrate data/computations to the type system/compile time, it makes sense that they would yield a more efficient binary than the analogous non-template case as long as optimization/inlining were applied ideally to each case
>>
wew lad
class MyClass
{
private:
static std::vector<char> s_mychars;

public:

class _init
{
public:
_init()
{
// some loop
s_mychars.push_back('a');
s_mychars.push_back('e');
s_mychars.push_back('i');
s_mychars.push_back('o');
s_mychars.push_back('u');
}
} ;

private:
static _init s_initializer;
};

std::vector<char> MyClass::s_mychars;
MyClass::_init MyClass::s_initializer;
>>
>>62041885
What's wrong?
>>
>>62041663
https://stackoverflow.com/questions/6996603/how-to-delete-a-file-or-folder

It's even in Python for ya
>>
>>62041001
Good show lad.
>>
>>62041663
https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/bin/rm/rm.c?rev=1.42&content-type=text/x-cvsweb-markup
>>
>>62041953
>_init()
> {
> // some loop
> s_mychars.push_back('a');
> s_mychars.push_back('e');
> s_mychars.push_back('i');
> s_mychars.push_back('o');
> s_mychars.push_back('u');
> }
Fucken C++. Static structures when?
>>
>>62041663
yeah of course

>>62041984
>stackoverflow
never post again
>>
>>62041885
>not doing this
>>
>>62041885
That's actually the correct way, anon.
>>
>>62037778
>>62037777
>>
int
main
(
)}
>>
>>62042018
>this upset about a correct, succinct answer because it's on a website you don't like
>>
File: 93c.jpg (167KB, 800x600px) Image search: [Google]
93c.jpg
167KB, 800x600px
>>62042085

int
main(void)
{
>>
>>62042101
>correct, succinct answer
>cuckoverflow
pick 1
>>
>>62042138
Thank you for confirming you couldn't be bothered to open the link
>>
File: vlcsnap-2015-01-01-00h12m10s161.png (574KB, 1280x720px) Image search: [Google]
vlcsnap-2015-01-01-00h12m10s161.png
574KB, 1280x720px
Hello dpt, I'm in deep shit. By trade I'm an animator, recently in game dev. The studio I was at was run by a nutjob and couldn't pay us. I'm basically a failure because I can't find a new job.

I have about 2-3 months before I run out of money completely. Ten years ago I did a couple college programming courses, but I'm mostly a newb. Is there any good programming/ coding path from here to non-intern employment in the time I have left?

I've been looking into C# but don't think I could learn enough to get another game industry job (or go indie). Python is the other option I see, because it's used in technical animation jobs which is related to what I did before, but I still wouldn't have all the experience they require.

If gaining viable skills isn't feasible in a short time, I may as well start a Patreon for my art shit and play vidya while waiting for a job offer. Maybe I should just self terminate.
>>
>>62042152
I blocked cuckoverflow in my hosts file, along with other FAKE NEWS sites like CNN, Breitbart, Fox News etc
>>
>>62042175
Stop posting anytime.
>>
>>62042190
no u
>>
>>62042175
Just use an ad blocker, you won't be giving money to them.
>>
what is ladder logic? not a programmer and was reading about embedded electronics in cars (ecu)
>>
std::array is useless
>>
>>62042352
How come? It's essentially a compile-time size array that works with STL.
>>
>>62037763
Template?
>>
>>62042264
One language used to program PLCs. It looks like the schematics for literal relay logic with a live vertical rail on the left, relays and coils connected in horizontal lines, and a vertical return on the right. the lines look like the rungs of a ladder, hence the name.
>>
>>62039370
He's looking at her ass, not her face
>>
Do you agree with this answer: https://stackoverflow.com/a/28990895 that these days you should return or pass by reference or value based on whether it is logical instead of performance considerations (for the most part)?
>>
>>62041953
why are you using push_back?
or a better question: why aren't you using the initializer list constructor for the vector?
std::vector<char> v{'a','b','c','d'};

perhaps you should read a book
>>
>>62042484
Neither one is less readable than the other, so I'll go for the option that gives me the best performance.
>>
>>62039509

You can if you look at the source code, which any grader worth their salt will do.
>>
File: dead esoteric languages.png (56KB, 705x556px) Image search: [Google]
dead esoteric languages.png
56KB, 705x556px
What's the most outdated language?
>>
>>62042558
FORTRAN
>>
>>62042558
C
>>
>>62042558
Go
>>
>>62042558
C/C++, Anything prior to those, etc
>>
>>62039419
void rand_sequence(int * your_array, int arr_size)
{
int i = 0;
int aux = 0;

int * checker = (int*)malloc((arr_size) * sizeof(int));

memset(checker, (-1) , arr_size * (sizeof(int)));

for (i = 0; i < arr_size; )
{
aux = rand() % arr_size;

while (*(checker + aux) != -1)
{
aux = aux + 1;

if (aux == arr_size)
{
aux = 0;
}
}

*(checker + aux) = 1;

*(your_array + i) = aux;

i = i + 1;
}

free(checker);
}
>>
>>62042586
Why are you casting the return value of a malloc()?
>>
>>62042558
Probably FORTRAN honestly. Even the languages from around the same time like ALGOL and Lisp are way better than it
>>
>>62042558
C++ and anything prior to that
>>
>>62042598
He's casting it to a pointer, so it's going to be the same size as size_t on any usable architecture anyway.
>>
>>62042598
Because C++ retards are retards
>>
>>62042598
>>62042586
hime? is that you?
>>
>>62042586
honestly, I never use malloc, I just search on internet and in the example that I read they were casting the return value, now that you ask, I made a simple search and I found that it's necesary if you want to compile C++ code using malloc...
>>
wweeww lads
class Humidity;

class Temperature {
private:
int m_temp;

public:
Temperature(int temp = 0) { m_temp = temp; }

friend void printWeather(const Temperature& temperature,
const Humidity& humidity);
};

class Humidity {
private:
int m_humidity;

public:
Humidity(int humidity = 0) { m_humidity = humidity; }

friend void printWeather(const Temperature& temperature,
const Humidity& humidity);
};

void printWeather(const Temperature& temperature, const Humidity& humidity) {
std::cout << "The temperature is " << temperature.m_temp
<< " and the humidity is " << humidity.m_humidity << '\n';
}

int main() {
Humidity hum(10);
Temperature temp(12);

printWeather(temp, hum);

return 0;
}
>>
>>62042598
Because casting malloc makes the C code more compatible with C++.
>>
>>62042586
You should seed the random number generation.
>>
>>62042654
wew lad
#include <cstdio>

struct Weather
{
int temperature = 0;
int humidity = 0;
};

static void print_weather(const Weather &weather)
{
std::printf("The temperature is %d and the humidity is %d.\n", weather.temperature, weather.humidity);
}

int main(int, const char **)
{
print_weather(Weather{12, 10});
return 0;
}
>>
>>62042680
>struct
>>
yeah, struct
>>
>>62042677
or you can do it in your main function...
>>
>>62042687
saves a keyword, otherwise it would have had to be written as:
class Weather
{
public:
int temperature = 0;
int humidity = 0;
};
>>
new thread:
>>62042734
>>
sometimes the thought crosses my mind that i alone may be intelligent enough for c++.
i trust nobody with that language, they are all bumbling retards, but i might be smart enough to use some of it's features while mostly writing regular c.
mostly operator overloading, that's kinda cool
but in reality what i want is a version of c with a better syntax, things like the address operator, pointer dereferencing, and other shit all suck really hard.
i want a better version of c, and thoughts on it have crossed my mind many times because of that.
help.
>>
>>62040644
>A huge waste of memory can represent cyclical data structures.
ftfy
literally just use an approach that works with ordinary arrays plus some appended indication that it's cyclical, e.g. "cyclical[1,2,3]" vs. "[1,2,3]"
>>
want to create a desktop application to help manage my daily life, I'm a bit slow when it comes to keeping track of different tasks, so would prefer to consolidate those into 1 instead of relying on multiple programs to do it for me (rainmeter, rainlendar etc). What's a good language to develop in that would also allow me to add/remove components as desired (I eventually also want to add charts etc so i can have decent reporting and tracking on how well im taking care of myself), and also supports synchronizing (small data upload/download for when im out and using my phone).
>>
File: 1503433048336.jpg (35KB, 367x458px) Image search: [Google]
1503433048336.jpg
35KB, 367x458px
where is THE place to learn cpp lads?
Thread posts: 319
Thread images: 26


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.