[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: 314
Thread images: 22

What are you working on, /g/?

Old thread: >>59505732
>>
nth for rewriting the linux kernel in basic
>>
>>59511103
Which BASIC?
>>
>>59511107
he's doing it in visual basic
>>
>>59511107
M$ of course
then
>>59511126
>>
>>59511126
Which Visual Basic?
>>
File: 1452400586237.gif (232KB, 500x281px) Image search: [Google]
1452400586237.gif
232KB, 500x281px
>>59511143
see >>59511139
>>
>>59511169
The only version that matters
S E V E N 
E
V
E
N
>>
In a doubly linked list, how would you go about switching two nodes where you don't know there positions within the list when using pseudo code?
>>
>>59511202
just swap their values
>>
>>59511198
wait, so you write in .NET VB?
>>
>>59511202

You mean with pointers?

switchNodes(Node* n1, Node* n2) {
Node* nodeTMP;

nodeTMP = n1;
n1 = n2;
n2 = nodeTMP;
free(nodeTMP);
}
>>
>>59511292
In hell, im just shitposting
>>
>>59511202
(rotatef (nth (position h l) l)
(nth (position g l) l))
>>
Why I can't have functional programming in C just passing function pointers?
>>
>>59511375
>just passing function pointers?
Because FP was designed to get away from shitty c hacks
>>
>>59511391
>Instead you have to assign sqrt(2) to a temporary variable, and then add 1 to that.
I can do that, but why would I need that?

>>59511420
>from shitty c hacks
Such as?
>>
>>59511420
But FP came before C, anon.
>>
>>59511202

def switch_nodes(a, b):
a, b = b, a
>>
>>59511080
>>59511080
Wooby a cute!
>>
>>59511375
C's type system isn't very good tbdesu
>>
I'm shit at programming and should just kill myself
>>
>>59511516
What's bad with type system?
>>
>>59511375
>>59511516
also lambdas amd closures
>>
>>59511518
Learn Lisp.
>>
>>59511529
no proper polymorphism of any kind
(not OOP polymorphism)

just (non type safe) void pointers
>>
>>59511446

>Such as?

Not him, but the whole idea of using something like a map-/forEach-iterator is that you can't access anything outside the members of the given collection.

If you use pointers you have the problem that they can (theoretically) point to anywhere. A completely different logic with differnt pitfalls.
>>
>>59511529
every fucking thing is a void*, you can't even call that a type system.
>>
>>59511555
Are you saying the function that is mapped over a collection cannot access anything other than the elements of said collection?
>>
>>59511375
How would that even work?
Something like this?
void *map(void (*fp)(void *arg), void *data, size_t size)
{
void *out = malloc(size);
for (size_t i = 0; i < size; ++i) {
*(i + out) = fp(*(i + data));
}

return out;
}
>>
>>59511551
>no proper polymorphism of any kind
Isn't that a result of strong typing?
>>
>>59511656
C is weakly typed
>>
>>59511656
No, you can have strongly typed polymorphism.
>>
>>59511655
Exactly. Also, checked.
>>
>>59511655
>
void *map(void (*fp)(void *arg), void *data, size_t size)
{
void *out = malloc(size);
for (size_t i = 0; i < size; ++i) {
*(i + out) = fp(*(i + data));
}

return out;
}


absolutely gross
>>
>>59511738
ur shit
>>
>>59511655
>
*(i + out) = fp(*(i + data));

Wrong.
*(i+data)
has type void and the mapping function takes a void*. Also, I don't even know what would be returned by dereferencing a void*.
>>
Building a neural network over here
>>
File: 1361391635.gif (510KB, 500x283px) Image search: [Google]
1361391635.gif
510KB, 500x283px
>>59511800
Are you trying to build an AI waifu?
>>
>>59511844
Yes, that is what I'd like to achieve someday (but I'm startIng out simple)
>>
where would /dpt/ rather work:

failing startup
or
incompetent corporate giant
>>
>>59511869
failing startup

You'll still get paid 100k for a year or two and be able to plan out your next job.
>>
>>59511764
>Also, I don't even know what would be returned by dereferencing a void*.
You can't.
>>
>>59511687
Haskell is a nice example
>>
>>59511655
>everyone here shitting on c++
>somehow defending this void* mess
>>
>>59511876
but what about soulsucking crunches, bro culture and sexual harassment anon
>>
>>59511869
Incompetent corporate giant ofc, in big companies no one notices you're dicking on the internet all day long instead of doing your job.
t. work in a relatively big company
>>
>>59511869
Incompetent corporate giant

I wouldn't have to do shit. Either that or I look like a god because I'm the only competent one.
>>
>>59511901
CL-USER> (mapcar (constantly 'garbage) '(c c++ rust python haskell))
(GARBAGE GARBAGE GARBAGE GARBAGE GARBAGE)
>>
>>59511898
That's what I figured.

>>59511901
Wanna write that as a generic for us?
>>
>>59511901
At least void* isn't template
>>
>>59511934

// input type, result type
r* map<i, r> (r(*fp)(i), i* data, size_t)
>>
>>59511935
Obviously, void* is slower and less safe.
>>
>>59511977
void* isn't slower and templates are less safe
>>
>>59511869
Depends on the role. For junior or mid-level, corporate giant. Either they've got a lot of room for improvements or they're just looking for someone to help maintain the monolith and do smaller projects, and no one's riding you to work 80 hours to work on "it's [successful startup] but [adjective]" so you get to go home at the end of the day and have time to do whatever you want.

I've heard startups are cooler for the extremes of the skill ladder (juniors or veteran devs); my friend is currently working at some corporate giant in NY and it's torture because he's in meetings almost constantly instead of being allowed to actually program.
>>
File: deskosicp.jpg (198KB, 1440x810px) Image search: [Google]
deskosicp.jpg
198KB, 1440x810px
>indians rewriting Linux kernel to be OOP
https://www.bosslinux.in/boss-mool

does it have uses/advantages/future programming wise in your opinion, or it's just another case of poo.init()?
>>
>>59512041
unlikely to be a good thing
>>
>>59511995
void* is slower because it forces to use full-wide pointer even for trivial shit like uint8_t and because monomorphisation allows better optimization. void* is less safe because it doesn't enforce type safety.
You claiming otherwise just show how little you understand.
>>
>>59512041
More like POO/Linux, or as I’ve recently taken to calling it, POO plus Linux.
>>
>>59512051
the """equivalent""" code would be
template <typename T>
... T* ...

(and even then that's not equivalent because it's instantiated and not actually polymorphic)
--
void* DOES enforce type safety, and templates don't
the difference is void* does not "remember" the type pointed to, but then it isn't supposed to anyway

temples only type check when instantiated, in C++ you might even have incorrect syntax and the compiler can't tell if the template isn't instantiated
>>
File: dt170321.gif (128KB, 900x280px) Image search: [Google]
dt170321.gif
128KB, 900x280px
LOL
>>
File: okcupid.png (36KB, 768x308px) Image search: [Google]
okcupid.png
36KB, 768x308px
https://tech.okcupid.com/rust-and-rpc-okcupid-hackweek-2017/
Meanwhile, OkCupid is close to using Rust in production.
>>
>>59512041
It would be worthwhile only in CLOS.
>>
>>59512109
basically, templates are just macros that can (in very specific contexts) have arguments inferred, and that can declare code at the top level

they aren't really polymorphic
>>
learning some python, i would like to do some scripts to pipeline stuff into for some utility stuff in bash, but i am kinda out of ideas, someone?
>>
>>59512172
import random
while True:
print(random.random())
>>
File: 1478036727555.jpg (47KB, 645x968px) Image search: [Google]
1478036727555.jpg
47KB, 645x968px
>tfw defending weak typing
>>
>>59512109
>the """equivalent""" code would be [..]
Equivalent to what? C++'s equivalent of map is http://en.cppreference.com/w/cpp/algorithm/transform, C++'s equivalent to malloc of void*'s is a vector with values stored in-place. If you want to use a pointer you just use "MyType*" as a T. Check http://martin-ueding.de/en/articles/qsort-vs-std-sort/index.html for comparison of std::sort with qsort, the latter being an example of void* mentality, std::sort BTFO it.
>void* does not "remember" the type pointed to
>void* DOES enforce type safety,
What, are you even serious now?
>in C++ you might even have incorrect syntax and the compiler can't tell if the template isn't instantiated
Yes, so? Non-instantiated template code doesn't compile at all, it's not like you lose some safety because of it.
>>
>>59512115
Do those coffee warmers actually work?
I might just buy one.
>>
>>59512253
this
these template fags need to fuck off
we don't need your macros
>>
>>59512115
I don't get it
>>
Getting destroyed by trying to implement Dijkstra's algorithm with a custom class.

Say I have the following structure:
struct Index
{
int col, row;
Index( int c, int r): col(c), row(r) {}

friend ostream& operator<<(ostream& out, const Index& ind)
{
out << "(" << ind.col << ", "<< ind.row << ")";
return out;
}

friend bool operator==(const Index& lhs, const Index& rhs)
{ return (lhs.col == rhs.col && lhs.row == rhs.row); }
friend bool operator < (const Index& x, const Index& y)
{ return !(x==y); } //Because two elements in a set are "equal" if "<" evaluates to true,
//I figured simply seeing if they weren't equal was good enough.

Index& operator=(const Index& src)
{
this->col = src.col;
this->row = src.row;
return *this;
}
};


When I iterate through an n x n matrix, adding an Index initialized with (col, row) to a set, I found out that (a) there were multiple copies of an index within a set, and b) does not check if the set contains an Index correctly... What am I doing wrong?
>>
>there are retards ITT comparing static metaprogramming to runtime polymorphism
>>
>>59512254
vectors use a pointer too
if you wanted a better example you would have used something where it references the type directly, e.g.

template <typename T>
struct Named {
T x;
string name;
}


and again, not equivalent to a void pointer

>>void* does not "remember" the type pointed to
>>void* DOES enforce type safety,
>What, are you even serious now?
Yes, it ensures that things that are void pointers and things that are not do not match.

>Yes, so? Non-instantiated template code doesn't compile at all, it's not like you lose some safety because of it.
i'm sure there's nothing wrong with a system which people are supposed to use for generics can fail despite compiling

it's not like there have been tons of problems with people when the template is instantiated, or even instantiated with a different type
it's not like C++ has awful errors
it's not like people might #include a library with templates and instantiate it differently
>>
File: confusion.jpg (20KB, 490x488px) Image search: [Google]
confusion.jpg
20KB, 490x488px
Stupid osdev question:
do each processor needs a separate idt and gdt table?
>>
I want to have some bignums in C.
My bignum type is built on BCD, and benefits by being theoretically unlimited, since it uses unused values to mark decimal point and the end of number. Like:
127.38482804727491

would be equal to (in hexadecimal)
127A384828047274910F

I think I have to read values as strings, so I think it's going to look like
new_bignum(a, "127.245")

where a is going to be some pointer.
I will post my implementation soon, stay tuned.
How would you solve this problem in your language?
>>
>>59512351
Void can point to any data type, and you have to cast it to use it. It doesn't do type checking.

>>59512282
His coffee got cold.
>>
>>59512370
Store the 10^k and 10^-l separately.
>>
>>59512346
This. void* (and similarily
interface{}
) is the worst form of generics as it requires indirection and throws type safety out of the window. It is the sign of weak language.
>>
>>59512367
Yes, every processor has it's own control registers assoc. with idt/paging ect
>>
>>59512393
Why?
>>
Trying to figure out why this code doesn't work

https://github.com/radioman/WebRtc.NET/issues/43
>>
Clojure is statistically typed.
>>
File: 1367519246134.jpg (30KB, 480x493px) Image search: [Google]
1367519246134.jpg
30KB, 480x493px
>>59512410
Ah thanks
>>
>>59512333
show set instantiation/adding + checking Index's to the set code.
>>
How would you implement something like
int foo ( template <T> int (*func)(T) ) {
return foo<int>(3) + foo<double>(3.5);
}

in a C++-like language?
>>
>>59511080
clock_t clockT = clock();
time_t timeT = time();


What is the difference ?
What is best to measure the run time of my sorting procedure?

Give me one good argument that attest "functional programming is better than OPP in some cases"
>>
>>59512458
What does it do?
>>
>>59512406
wrong

>>59512392
>can point to any data type
and?
you can even do this in Haskell
data Box = forall a. Box a

>you have to cast it to use it
no, you can use it as a void pointer all you like
you can store it, copy it, move it around
you have to unsafely cast in order to treat it as a specific type
that's type safety
you know what isn't type safety?

template <typename T>
T add(T a, T b) { return a + b; }
>>
>>59512417
I worked for a webrtc project. Lots of javascript and shit.
My company later bought Alcatel Lucent's webrtc.
Is this still a relevant technology?
>>
>>59512458
if it's only done at compile time, you would have to instead use a struct, and it would be part of a template <template <typename> t> parameter and it would be god awful on both sides
>>
>>59512468
It takes a generic function as an argument and instantiates it in different ways at runtime
>>
>>59512351
>equivalent to a void pointer
Can we agree that qsort is a typical void* solution, and std::sort is it's equivalent? Because it seems so and qsort is being destroyed by std::sort.
>Yes, it ensures that things that are void pointers and things that are not do not match.
So you're saying type erasure is somehow type safe? Do you even know what "type safe" is?
>i'm sure there's nothing wrong with a system which people are supposed to use for generics can fail despite compiling
It looks like you're confused, it's not like bogus template code can just find its way into resulting binary without any checks. If template code isn't instantiated then it's not compiled at all.
>>
>>59512439
    set<Index> hasSeen; //set instantiation
priority_queue<Node> paths; //Node has the following structure: Node.ind (Index),
//Node.weight (long), the latter keeps track of path length
/* set up priority queue */

while(!paths.empty() )
{
Node currNode = paths.top();//Take an element out of the "to-do" list
paths.pop();

Index currInd(currNode.ind.col, currNode.ind.row); //Index initialization
if(hasSeen.count(currInd))
continue; //If you've seen a node, then skip it (because it won't be the most efficient path to get to an index)

hasSeen.insert(currInd); //Insertion
cout << hasSeen.size() << endl; //When it runs on a 5 x 5 matrix, we end up with 33 entries, which clearly means
//Some indeces are being added twice

>>
>>59512471
I think we have very different ideas of type safety.
Also much of C++'s weird shitty type rules come from it being aggressively weakly-typed
>>
>>59512406
I didn't mean it's worse. It's just different. Static != runtime. Templates were introduced to allow some form of static genericity. Thus it is quite stupid to compare them. The corresponding C++ feature would be dynamic casting.
>>
>>59512534
>Can we agree that qsort is a typical void* solution, and std::sort is it's equivalent? Because it seems so and qsort is being destroyed by std::sort.
that's probably because std sort uses operator< whilst qsort uses a function pointer

>So you're saying type erasure is somehow type safe? Do you even know what "type safe" is?
i don't know what you mean by type erasure, but void pointers in C are type safe
the only thing that isn't type safe is casting, which can be done with any pointer


>It looks like you're confused, it's not like bogus template code can just find its way into resulting binary without any checks. If template code isn't instantiated then it's not compiled at all.
if nobody was ever going to use it (or had ever used it), it wouldn't be in the source
>>
>>59512561
Yeah but the problem with C and Go is that there is literally no way to do statically checked generics. If a language had both then that would be great because dynamic generic behavior is often useful (this is essentially what OOP tries to solve).
>>
how do i return a template from a function in c++
let's say it takes two ints and returns a template
>>
>>59512551
void* is exactly what it is supposed to be, and the weak typing of C is do to
1) lack of discriminated unions and pattern matching (hello C++!)
2) casting (hello C++ inheritance!)
3) generally avoiding using types because of the clunkiness (C++ is better at this but still not great)
>>
>>59511865
Whts ur long term goal anon, Im thinking eventually when my resume allows it Ill apply to googles ai department because of there resources, or IBM but leaning towards google more
>>
I saw in the last thread people were drawing circles in terminal.

I feel like adding some code that they probably didn't know about:
 // this is simply the midpoint circle algorithm for drawing a circle;
// it is a variant of Bresenham's line algorithm, and is thus sometimes
// known as Bresenham's circle algorithm;
// see additional info:
// http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
// http://www.mathsisfun.com/algebra/circle-equations.html
// http://members.chello.at/~easyfilter/bresenham.html
void GLCD_draw_circle( int x0, int y0, int radius)
{
int x = radius, y = 0;
int xChange = 1 - (radius << 1);
int yChange = 0;
int radiusError = 0;

while (x >= y)
{
GLCD_PutPixel(x + x0, y + y0); // call of GCLD function;
GLCD_PutPixel(y + x0, x + y0);
GLCD_PutPixel(-x + x0, y + y0);
GLCD_PutPixel(-y + x0, x + y0);
GLCD_PutPixel(-x + x0, -y + y0);
GLCD_PutPixel(-y + x0, -x + y0);
GLCD_PutPixel(x + x0, -y + y0);
GLCD_PutPixel(y + x0, -x + y0);

y++;
radiusError += yChange;
yChange += 2;
if (((radiusError << 1) + xChange) > 0)
{
x--;
radiusError += xChange;
xChange += 2;
}
}
}



Specifically, this code uses no trig. I don't think I was able to decipher how it worked but I only glanced at the source. EE, this was for an ARM system with a 320x240 LCD.
>>
>>59512458
>>59512494
Not exactly certain what you're actually trying to do, but in C# this would be something like:
int foo<T>(this Func<T> func) => foo<int>(() => 3) + foo<double>(() => 3.5);

whereas the explicit types aren't really necessary, so it's just
int foo<T>(this Func<T> func) => foo(() => 3) + foo(() => 3.5);

but you're approaching dynamic typing if you want to be able to replace 3 and 3.5 with supplied values.
>>
>>59512606
You don't.
>>
>>59512588
>if nobody was ever going to use it (or had ever used it), it wouldn't be in the source
template <typename T>
int middle(const T& arr) {
return arr[arr.size() / 2];
}

int main(void) {
std::string text = "hello";
char c = middle(text);
std::vector<int> v { 1, 2, 3 };
int k = middle(v);
// middle(3) would be an error, but since you never called it like that, the erroneous code is never generated. But that doesn't mean I'm not using the function.
// meanwhile, this generic function is easy to use, works for any kind of crazy container with different ways of representing size() and [], I don't have to pass function pointers around, it's easier to optimize, etc.
}


The cases where templates might instantiate syntactically invalid code are very rare, but I would agree that they are somewhat of a problem.
>>
>>59512639
when someone else instantiates it or when you instantiate it differently

you are "using the template" but not a certain instance
>>
>>59512620
Sorry, it was supposed to be
void foo( template <typename T> int (*func)(T) ) {
return func<int>(3) + func<double>(3.0);
}


Here foo is not generic but its argument is a generic function
>>
>>59512253
Literally only argument against strong typing is that it's hard, do this is pretty accurate.
>>
>>59512537
Your problem is with your operator<() definition I think. As an aside, you can use the <tuples> library, something like tuple<int, int> point = make_tuple(row, col); if(mySet.find(point) != mySet.end()) continue; else mySet.insert(point);
>>
>>59512699
in many languages like C++ it's clunky
>>
>>59512370
I have a BigInt library I've partially implemented in Lua. Basically, it's a list of numbers of modulo radix to the radix**i power at index i, just like a normal number, but the base is 2^26.

Then I use your typical algorithms you learn in grade school to implement arithmetic. Currently I don't have divide and remainder implemented, but soon.
>>
>>59512699
I find weak typing much harder to read desu
>>
>>59512699
Weak typing was a fad because it seemed nice that the programmer could make mistakes and the compiler could fix them. But now it's agreed that it's a shitshow because now you can have this ambiguous code that the compiler is trying to "fix" and does so incorrectly, that or it's just really hard to tell what exactly the compiler is going to do because weak typing rules are usually complicated and entirely implicit. Explicit code is more tedious but in the end its usually worth it
>>
>>59512714
C++ is also a humongous Price of trash
>>
>>59512370

>I want to have some bignums in C.

Learn from the best:
>https://github.com/ruby/ruby/blob/trunk/bignum.c
>>
>>59512736
>Price of trash
>>
>>59512370
>How would you solve this problem in your language?
I would use the built in Integer or Rational types, of course.
>>
>>59512623
stupidest fuckin language in the world, hands down
can't return a template
can't declare a pointer to a template
can't declare a pointer to the entire program stack
can't make an array of voids ( has to be void POINTERS, gay as fuck )
can't create a void literal
compiles pure private virtual bullshit for no reason
c++ is trash okay
>>
>>59512771
Brb making a language with all those features
>>
>>59512771
>can't create a void literal
[](){}()
>>
>>59512771
You sound mad as fuck at a programming language.
>>
>>59512699
Compiletime inference is kind of pushing the hardness away.
>>
>>59512616
draws both sides of the circle at once, 1 pixel per line? (or w/e a pixel is defined as anyway) how, idk, i see a bit operator so its out of my knowledge base. pretty cool tho
>>
File: anal beads.png (4KB, 631x63px) Image search: [Google]
anal beads.png
4KB, 631x63px
>>59512660
Something like this?

Takes a generic function that returns an int, and two generic arguments to hand to said function.

public static int Foo<T>(this Func<T, int> func, T ayy, T lmao) => func(ayy) + func(lmao);


var output = new Func<double, int>(x => (int)x).Foo(1, 2);
>>
File: bone-think.jpg (144KB, 572x303px) Image search: [Google]
bone-think.jpg
144KB, 572x303px
>>59512712
Tuples worked! Thank you!

Just out of curiosity though, would you have any suggestions for a "<" operator? I'm probably going to be using similar coordinate systems so I want to make sure I create a good "Index" class/struct
>>
>>59512844
the type parameter should not be on Foo
>>
>>59512844
No, you have to be able to pass the function that you got as an argument two values of completely different types. Something like
static int Foo(Func<T,int> func) { return func<int>(3) + func<double>("hello"); }
>>
>>59512897
Shit, should be func<string>("hello")
>>
>>59512844
>>59512897
something like
Foo(Func<T, int> func<T>)
>>
>>59512699
Ruby BTFO?
>>
>>59512912
ruby doesn't need to be BTFO, everyone has always known it was trash
>>
>>59512897
I can't understand what you're actually trying to do when you put specific things like 3 and "Hello" directly into what is ostensibly supposed to work for any given type.

Do you want the function written to contain arbitrary values, or able to work with any values you pass into it and end up as an integer when all is said and done?
>>
>>59512919
Meant the tripfag, but the language too I suppose.
>>
>>59512937
I did too
>>
>>59512962
I thought it preferred xim?
>>
>>59512730
>everyone should suffer for the mistakes of the incompetent
fuck off communist.
>>
>>59512804
c++ is more like cuck++
can't make a pointer to the bare metal
can't return a header file from a function
can't return an entire program stack from a function
can't do self-modifying code
can only return int from main, can't return a pointer, a reference, a floater, a struct, a class, a template, or a header
can't do definite integrals, have to use shitty rectangle or trapezoid (((approximations)))
can't make a static volatile
can't make a const volatile
can't make a public private or a private public
has private-default class (class), public-default class (struct), but no protected-default class
bools take up a byte instead of a bit. gross waste of memory
no floating-point boolean
can't do a while(false) loop
it's cuuuuuuucked
>>
>>59512976
no, she prefers "he"
>>
Thinking of writing an encrypted P2P chat server in C with "channels" to receive public messages between the people you connect with
What do you think?
>>
>>59512931
The goal is something like
void serializeThings(Func<OutputStream,T,void> serialize, OutputStream output) {
serialize<int>(this.employees.Length);
for (Person p : this.employees) {
serialize<Person>(output, p);
}
serialize<int>(this.upcoming.Length);
for (Event e : this.upcoming) {
serialize<Event>(output, e);
}
}

void serializeReadable<T> (OutputStream output, T data) {
// human readable output format
}

void serializeCompressed<T> (OutputStream output, T data) {
// compressed output format
}

void serializeObfuscated<T> (OutputStream output, T data) {
// obfuscated output format
}

...
seralizeThings(serializeReadable, openOutputFile("readable.txt"));
seralizeThings(serializeObfuscated, openOutputFile("obfuscated.bin"));


I think this is actually doable in Java, but definitely not in C++.
>>
>>59512846
It should work if it looked something like: bool operator<(const Index & x, const Index & y) { if(x.row < y.row) return true; if(x.row > y.row) return false; if(x.col< y.col) return true; return false; //take care of x.row > y.row and x == y}

This should work, considering how 2D arrays "flatten" when placed sequentially in memory, i.e. all row 1 after all row 0.
>>
>>59513023
>encrypted P2P chat server in C
>in C
Dropped.
>>
>>59512912
What happen?
>>
>>59513053
It's not that hard to write C anon. trust yourself
>>
>>59512254
>Check http://martin-ueding.de/en/articles/qsort-vs-std-sort/index.html for comparison of std::sort with qsort, the latter being an example of void* mentality, std::sort BTFO it.
Has nothing to do with void * vs template but the fact that std::sort definition is in the header file so the compiler can easily inline the comparison function.
It doesn't even have to do with qsort taking a function pointer - modern compilers can inline them if they have the full definition if the caller and callee, so if you dump all the qsort code into stdlib.h or do an "include qsort.c" you'll get similar performance.
>>
>>59512588
>that's probably because std sort uses operator< whilst qsort uses a function pointer
And how overloaded operator<() is different from a function pointer? It's a user-supplied code in both cases. Also there is an overloading with explicit comparison function: http://en.cppreference.com/w/cpp/algorithm/sort . The difference is, since std::sort knows the code of operator<() at compile time it can inline it on monomorphisatoin, resulting in operator<() being replaced with actual < for trivial types. You can never do this kind of optimizations with void* mentality.
>void pointers are type safe but using void pointer is unsafe
Wew, lad. Meanwhile template code are actually type safe with types being checked at compile time.
>if nobody was ever going to use it (or had ever used it), it wouldn't be in the source
How is this different from a macro in C source no one uses tho?
>>
>>59513138
>And how overloaded operator<() is different from a function pointer? It's a user-supplied code in both cases.
run-time vs compile time
i don't think C compilers analyse and inline that argument when it's given a static input

>void pointers are type safe but using void pointer is unsafe
I didn't say this. Using void pointers is safe.
Void pointers are type safe - they're a fucking type.
Casting is unsafe, and that's got nothing to do with void pointers.

Template code is not type safe, as I pointed out.
It's simply a slightly better macro.

>How is this different from a macro in C source no one uses tho?
it isn't
>>
>>59513138
>You can never do this kind of optimizations with void* mentality.
Both gcc and clang can.
>>
>>59513055
Previous thread he was defending weak typing and his argument boiled down to it being easier to create an unmaintainable garbage pile.
>>
>>59512842
At actually draws 8 arcs at a time, up to 45 degrees from the reference. It made it very useful for our Pacman project.
>>
>>59512998
You're a monster.
>>
File: 1435932629195.gif (622KB, 500x375px) Image search: [Google]
1435932629195.gif
622KB, 500x375px
>want to write a simple OS
>modern computer hardware too complicated and daunting

>want to build a simple computer for the simple OS
>building a computer powerful enough for a Unix-like OS is too hard and time consuming

i'm a failure.
>>
>>59513259
A friend of mine is a Computer Engineer and his team had to do an OS for their BS final project.

They didn't succeed, but it was the rest of the team, not because of his memory paging system.
>>
>>59513259
Terry succeeded
>>
>>59513259
There's plenty of places to start, people build operating systems for educational purposes all the time.
>literally courses on operating system design
>literally online how-to RTOS on a pi
>literally all old simple god chip hardware available on the cheap
>microcontrollers available for pennies

You're really just a failure for reasons other than that.
>>
File: 1350168930860.jpg (5KB, 210x216px) Image search: [Google]
1350168930860.jpg
5KB, 210x216px
It says here that you "cross-dress to improve programmer efficiency"?
>>
>>59513162
> i don't think C compilers analyse and inline that argument when it's given a static input
EXACTLY. Because it can't. And C++ code with templates can and does. This is why templates faster than void*, and has been shown above.
> Casting is unsafe
So you can't do anything useful with pointer without being unsafe.
> Template code is not type safe
Successfully instantiated template code is type safe, and it's instantiated template code that gets compiled.
> it isn't
So how
#define BROKEN_MACRO do{ broken sutff } while (0);

is different from
template<T>
T broken_function(T t) {
broken stuff
}

? Both never used thus never compiled.

>>59513176
No they can't: https://godbolt.org/g/QQiK6w . You can see, qsort is compiled as a function call, while std::sort is inlined with the comparison function in it.
>>
>>59513340
Indeed, I occasionally wear stripped socks to improve my computing ability by 120%
>>
>>59513342
>Because it can't
it could if it checked

>So you can't do anything useful with pointer without being unsafe.
not only is that wrong, but it's wrong in a context of being wrong
if you have a fully polymorphic type, that could be ANY type, then you generally can't do anything useful with it, unless you're using a language where anything can be copied and returned and stored
C++ templates aren't type safe which is how they get around this, otherwise you'd need a shit ton of is_integral has_operator< or whatever

>so how ...
it isn't i literally said that
>>
>>59513340
>>59513360
into the trash it goes

all millennials and gay anal guinea homo SJW trash must die

round them all up into the factories and burn them as fuel, putting literally trillions of terawatts of crisp, clean energy onto the global power grid
>>
>>59512264
Think about a hot cup of coffee. Imagine, through which parts of the mug is all its heat being lost? Then think about whether those things actually work.

You'd be better off wrapping the mug with a wool jacket or something.
>>
>>59513277
And I'm failing my second semester for the second time.
I guess I have ways to go.

>>59513287
I don't have as many -tisms as he does, though.
Also, Diana & Terry is OTP.

>>59513293
Yeah, but I want to strike a balance between stuff like https://www.youtube.com/watch?v=35zLnS3fXeA and an FPGA board.
Not as simple, because even a 16 bit CPU would completely overwhelm my electronics skills and patience.
I might end up using my RPi as hardware, though. Seems like the simplest solution.
>>
>>59513342
>>59513372
and since it's a pointer (in fact it's a specific monomorphic type), there are things you know you can do with it, it has a generic structure
>>
>>59513342
>No they can't: https://godbolt.org/g/QQiK6w . You can see, qsort is compiled as a function call, while std::sort is inlined with the comparison function in it.
see >>59513092

#include<stdio.h>
static int intcmp(void *a, void *b){
return *(int*)a - *(int*)b;
}
int foo(void *a, int n, int(*f)(void*, void*)){
void *m = a;
a = (char*)a + sizeof(int);
for(int i=1; i<n; ++i){


if(f(a, m) < 0) m = a;
a = (char*)a + sizeof(int);
}
return *(int*)m;
}
int main(int argc, char *argv[])
{
int a[] = {5,4,3,2,1};
int m = foo(a, 5, intcmp);
printf("%d\n", m);
}


clang turns that into printf("%d\n, 1); i.e constant folds the whole thing away.
>>
>>59513445
so to conclude, the only difference is that a template guarantees inlining, and that's because a template literally can't work at runtime
>>
>>59513381
CE here, I wrote my own 5-stage pipelined proc w/ BTB/Forwarding/L1/L2/prefetching ect in SystemVerilog. Some people in my class even wrote Tomasulo based processors. Was a really cool experience.
>>
>retards ITT are STILL arguing about unrelated compile-time vs runtime polymorphisms
>>
>>59513372
> it could if it checked
It can't check because functions compile separately. qsort is a separately compiled function, and so is the cmp function, and there is no contex in which C can produce a fused version. Meanwhile C++ is required to monomorphize templates on instantiation, produces specialized version of std::sort for every use. You can complain about code bloat, you the result is faster and safer code, and has been shown empirically.
> C++ templates aren't type safe which is how they get around this, otherwise you'd need a shit ton of is_integral has_operator< or whatever
The word you're looking for is bounded polymorphism. Yes, C++ can't limit the types you use as an argument for a template yet. It's called "concepts" in C++ and it's not
standardized yet. Still, C++ has "compile type duck-typing", so if you try to use a type in a way you're not suppose to in a template, your code won't compile. It doesn't mean it's type unsafe, since comple error isn't a runtime error. In the end, as I've said, successfully instantiated template code is type safe.
> it isn't i literally said that
Oh, right. So no point in arguing about that. I don't know why you even brought it up.
>>
>>59513504
>It can't check because functions compile separately. qsort is a separately compiled function, and so is the cmp function, and there is no contex in which C can produce a fused version.
Nothing forces you to do that, you can have everything in a single TU if you want.
>>
>>59513490
>unrelated
runtime polymorphism is better
you could have some way of indicating to the compiler that you're calling it at compile time

>>59513504
>It can't check because functions compile separately
And C++ can't export templates that way
So once again, it is a flaw in C++ that is causing the 'advantage'

>The word you're looking for is bounded polymorphism.
>concepts
and it's not going to be type safe because it won't be a requirement

>i don't even know why you brought it up
what? i said it's barely better than macros
then you said "so how is it any better than macros???"
then i said that again
then you said "so how is it any better than macros???"
then again
>>
>>59513561
>you can have everything in a single TU if you want
That kind of breaks the whole purpose of modularity (if you are ready to talk about such a thing in C).
>>
>>59513381
There's really a ton of options that aren't specifically raspi though, even old 6502 SoCs are available for basic stuff. Z80 I think has a kit now, too. There's a ton of old books on C64 ala terry.

There's also some options on like cortex-M which might be educational and useful in transitioning.
>>
>>59513485
Dang, dude. Is that what CE masterrace is like? I'm pretty sure most of my classmates have to relearn basic C++ whenever they get a new assignment.
>>
why do i need polymorphism in my life
>>
>>59513574
That's effectively what C++ templates forces you to do.
You can do that in C too if you want.
>>
>>59513622
code re-use
>>
>>59513629
>That's effectively what C++ templates forces you to do
I know. I hate how long C++ compile time gets because of it.
>>
object-oriented programming in C without void pointers
>>
>>59513629
It's not a feature, it's a limitation
In this case, the "benefit" is it's less expressive and so easier to optimise
>>
>>59513561
I don't want to have everything in a single TU, that's the point. I can achieve the same and even better results with templates.
>>59513568
>And C++ can't export templates that way
C++ can effectively export templates just by having them in a header. You still have to explain why std::sort is inlined and is inlining, while qsort is just a call.
>and it's not going to be type safe because it won't be a requirement
>type safe
You keep using the temp inappropriately. I've already said, the worst thing you can get with templates is a compile error, and compile error doesn't mean the language is type unsafe. Mean while the worst thing you can get with void* is much worse and you won't get it until sometime during runtime.
>>
object-oriented programming in assembly
>>
>>59513691
wrong
>>
>>59513697
Totally doable
>>
>>59513684
>I don't want to have everything in a single TU, that's the point.
You're gonna have to skip templates then until C++ gets proper modules, because right now you have to include the full definition every time you use a template.
>>
>>59513718
not okay
>>
http://www.drdobbs.com/embedded-systems/object-oriented-programming-in-assembly/184408319
>>
>To make a pointer variable NULL you assign it the value zero.

Which makes it null:
int *a;
a = 0;


or

int *a;
*a = 0;
>>
>>59513590
Dunno, I got lucky and got accepted to a very good Uni/found a group of smart friends to take classes with. I got to do a lot of neat stuff that I think most other schools just gloss over/don't cover at all.
>>
File: 1489446384132.jpg (19KB, 720x540px) Image search: [Google]
1489446384132.jpg
19KB, 720x540px
I know I'm most likely out of luck, but I need to program some shit ethereum database bullshit and can't find any documentation on how to translate the geth .ldb data into readable stuff, or at least how this data in encoded so I can write a decoder myself
>>
>>59513684
>C++ can effectively export templates just by having them in a header. You still have to explain why std::sort is inlined and is inlining, while qsort is just a call.
By having them in the header.
By having them in the header.
By having them in the header.

Which is because of a limitation.

And good compilers like clang, with access to the source, can inline.

>You keep using the temp inappropriately. I've already said, the worst thing you can get with templates is a compile error, and compile error doesn't mean the language is type unsafe. Mean while the worst thing you can get with void* is much worse and you won't get it until sometime during runtime.
I'm not using it incorrectly, you just can't understand.

template <typename T>
T add (T a, T b) { return a + b; }

this is NOT type safe
there is no + function for EVERY T
would you call a macro safe?
is an obviously faulty template that's never instantiated safe?

void* is a type
void* IS type safe

you don't get TYPE ERRORs are runtime using void*
you get other errors due to weak typing and becaues void* is normally standing in for something else

memory is a uniform representation for all types in languages like C and C++
>>
>>59513735
int *a = NULL;
>>
>>59513735
a = 0
Here we are "assigning to the pointer variable
>>
>>59513735
The first one. The second one is undefined behavior.
>>
>>59513735
>reassigning inits
>>
>>59511080
What's the best general programming book for someone starting out? I was wanting to get into Ruby.

But I would like to learn the logical part of problem solving, algorithms, and all that sort of stuff if possible in a single book.

What to do? Am I even in the right thread?
>>
we got a null pointer exception
>>
>>59513834
start with K&R C
>>
what in G*d's name fuck is going on here

void trans8(unsigned char* A, int m, int n, unsigned char* B) {
unsigned long long x, t;
int i;

for (i = 0; i <= 7; i++) {
x = x << 8 | A[m*i];
}

t = (x ^ (x >> 7)) & 0x00AA00AA00AA00AALL;
x = x ^ t ^ (t << 7);
t = (x ^ (x >> 14)) & 0x0000CCCC0000CCCCLL;
x = x ^ t ^ (t << 14);
t = (x ^ (x >> 28)) & 0x00000000F0F0F0F0LL;
x = x ^ t ^ (t << 28);

for (i = 7; i >= 0; i--) {
B[n*i] = x; x = x >> 8;
}
}
>>
>>59513804
So then everything is type safe in C because everything is just a pointer or an integer and the only errors you can get have to do with page faults from dereferencing bad pointers

Thats technically correct, but in real life programs have higher level ideas of types and its good to have a compiler that will be able to reason about, and catch at compile time (even if sometimes too far down the road, like what happens when you pass a struct to your generic add) type errors, e.g. errors having to do with data being used incorrectly, wrt the type of that data
>>
>>59513853
Is that the C programming language book with the big blue C on it?

Thanks anon. I know this question gets asked all the time here I'm sure. Thanks for the response.
>>
>>59513873
evil bit-level hacking
>>
>>59513834
>>59513853
C's okay though I prefer not to. Lisp is actually used a lot in education too especially for algorithm stuff. Ruby seems more tailored to handle text/string processing IMO, it's a fantastic replacement for perl.
>>
>>59513804
>this is NOT type safe
No, but add<int> or add<float> is, and it's not template<..> add what goes into the binary, it's add<int> or add<float>. In other words, as I've said, successfully instantiated template code is type safe.
Also, you're dense enough for me to agree what void* by itself is type safe, despite the fact being meaningless.
>you don't get TYPE ERRORs are runtime using void*
>you get other errors due to weak typing and becaues void* is normally standing in for something else
But that's exactly the point. If the system doesn't produce TYPE ERRORS and instead runs into RUN-TIME ERRORS, it's TYPE UNSAFE. Extensive type errors is a sign of type-safe system.
>>
>>59513880
C is really weakly typed, to the point you might call it unsafely typed, but the point is using void pointers is type safe whilst templates are not

In terms of the type system, this really means the kind of information you want to put into the types is seriously lacking

>>59513936
>No, but add<int> or add<float> is
And there's the problem

>But that's exactly the point. If the system doesn't produce TYPE ERRORS and instead runs into RUN-TIME ERRORS, it's TYPE UNSAFE. Extensive type errors is a sign of type-safe system.
That's the opposite of the truth.
Type safety means the system doesn't allow for many type errors or type checking errors to occur, or things you might consider to be so.
Run time errors are nothing to do with type safety, they're to do with strong typing.
Which C++ is also shit at.
>>
>>59511869
incompetent corporate startup so I can browse
the internet all day, or work on personal projects and get paid for doing little amount of work.
>>
>>59511080
Help me with vim.
vim's focus is at the bottom of the screen because I wrote more than 150 lines of code. Its hard to look down the screen all the time when cursor should in middle of screen.
How do I fix this?
>inb4 I don't wanna insert new line to get cursor to middle of screen.
>>
>>59513884
Yes, get the most recent edition
C is hard to start off on as a first language but the book is great.

honestly, if you have a CompSci background, if you read the first couple chapters of SCIP, then programming gets WAY easier on any language

Just my opinion ~desu
>>
>>59514053
>C is hard to start off
C is a beginner friendly newb language that people can learn in a week
>>
>>59513957
> Type safety means the system doesn't allow for many type errors or type checking errors to occur, or things you might consider to be so.
Wew, lad, so I've wasted all thit time on you only to realize you have no idea what you're talking about. Looks like you opened https://en.wikipedia.org/wiki/Type_safety, read the first sentence
>In computer science, type safety is the extent to which a programming language discourages or prevents type errors.
and closed it, without reading the second where they define "type errors":
>A type error is erroneous or undesirable program behaviour caused by a discrepancy between differing data types for the program's constants, variables, and methods (functions), e.g., treating an integer (int) as a floating-point number (float).
They aren't talking about type(-checking) error at compile time abut about the exact type of errors you get with void*.
But hey, I guess asm is the most type safe language out there because it has no types all and thus can't produce type checking errors.
>>
>>59511080
fn quicksort<T>(mut slice : &mut [T])
where T : std::cmp::PartialOrd + Copy
{
while slice.len() > 1 {
{
let (smaller_slice,greater_slice) = partition(slice);
quicksort(smaller_slice);
slice = greater_slice;
}
}
}


cargo build
Blocking waiting for file lock on build directory
Compiling quicksort v0.1.0 (file:///C:/Users/Olof/Desktop/Rust_stuff/quicksort)
error[E0502]: cannot borrow `*slice` as immutable because it is also borrowed as mutable
--> src\main.rs:63:11
|
63 | while slice.len() > 1 {
| ^^^^^ immutable borrow occurs here
64 | {
65 | let (smaller_slice,greater_slice) = partition(slice);
| ----- mutable borrow occurs here
...
70 | }
| - mutable borrow ends here

error[E0499]: cannot borrow `*slice` as mutable more than once at a time
--> src\main.rs:65:59
|
65 | let (smaller_slice,greater_slice) = partition(slice);
| ^^^^^
| |
| second mutable borrow occurs here
| first mutable borrow occurs here
...
70 | }
| - first borrow ends here

error[E0506]: cannot assign to `slice` because it is borrowed
--> src\main.rs:67:13
|
65 | let (smaller_slice,greater_slice) = partition(slice);
| ----- borrow of `slice` occurs here
66 | quicksort(smaller_slice);
67 | slice = greater_slice;
| ^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `slice` occurs here

error: aborting due to 3 previous errors

error: Could not compile `quicksort`.


(╯°□°)╯︵ ┻━┻)
>>
>>59514096
The compiler is telling you what went wrong
>>
>>59513873
magic constants
>>
>>59514117
magic isn't real you fuckin cuck
>>
>>59514076
>Wew, lad, so I've wasted all thit time on you only to realize you have no idea what you're talking about. Looks like you opened https://en.wikipedia.org/wiki/Type_safety, read the first sentence
I didn't learn the truth from Wikipedia, but it's cute that you needed to look it up

>They aren't talking about type(-checking) error at compile time abut about the exact type of errors you get with void*.
>But hey, I guess asm is the most type safe language out there because it has no types all and thus can't produce type checking errors.

You haven't understood what I or that was saying.
You are projecting your own types onto C and saying "it doesn't check these!".

void* does exactly what it's intended to do

When people cast void*, they are interpreting it as a particular type in order to call a particular function.
They are reinterpreting memory, and doing so intentionally.
C's memory model does not feature types.
All objects can be addressed, and all (non function) pointers can be cast to void*.
>>
>>59514096
For reference, the version with two recursive calls works fine. But rewriting it into a while loop as in CLRS makes the borrow checker murderous.

Do I need lifetime annotations or something?
>>
>>59514110
That doesn't help me if I don't know how to fix it. The algorithm itself is correct, the program just doesn't typecheck.
>>
>>59514136
You're potentially changing the length of slice inside a loop of the length of slice.
>>
>>59514166
I know what my algorithm does. I just want it to
1) borrow slice once for while loop check.
2) partition and split borrow into two subborrows
3) replace slice borrow with borrow of the smaller subslice.

But I'm not sure how to express this.
>>
>>59514096
>Rust
It seems that you fell for the placebo effect
>>
>>59512722
Speaking of which, what's a good algo that doesn't require trial subtraction? It's fine when the base is small, but when it's 2^26 it's an issue... it's a O(nlogn) op.
>>
->59514200
ExDEE
>>
C wizards it's your time to shine
why is this
typedef struct myStruct {
struct myStruct* next;
double d;
} myStruct;

myStruct* s = malloc(sizeof(myStruct));
s->next = NULL;

giving me this
Invalid write of size 8
==717== at 0x108A1B: main (main.c:43)
==717== Address 0x5201368 is 0 bytes after a block of size 8 alloc'd


Am I being meme'd or just stupid?
>>
>>59511080
Ruby is shit
>>
questions = ['what is a monotreme?',
'which a classic example of the inverse ratio between the size of a mouth and the size of a brain?',
' What is the airspeed velocity of an unladen swallow?'

]

answers = [
["a musical time keeper","a poisonous mammal","a train with one rail" ],
['nerd','geek','all of the above'],
['35 km/h', '50 km/h', 'A African or Euorpean swallow?']
]

usr_dict = {}


def question(number):
print(questions[number])
y=1
for x in answers[number]:
print(y,")",x)
y+=1
ans = input(">")
return answers[number][int(ans) - 1]


def ask_questions():
x= 0
for x in range(len(questions)):
usr_dict[questions[x]] = question(x)


def print_results():
for x in usr_dict:
print(x," = ", usr_dict.get(x))


ask_questions()
print_results()
>>
>>59514227
You have been memed into C that's what
>>
>>59513804
>this is NOT type safe
>there is no + function for EVERY T
The compiler will prevent you from trying to instantiate add with a T not implementing +.
>would you call a macro safe?
Macros clobber global namespace and will replace all references afterwards with its substituted expression, and can have unintentional side effects because of arguments being evaluated multiple times.
>is an obviously faulty template that's never instantiated safe?
Yes, obviously.
>>
>>59514245
Fuck off rust faggot
>>
>>59514257
Fuck off C tard
>>
>>59514251
>The compiler will prevent you from trying to instantiate add with a T not implementing +.
some TEMPLATE INSTANCES are safe, but TEMPLATES are not

>Macros clobber global namespace and will replace all references afterwards with its substituted expression, and can have unintentional side effects because of arguments being evaluated multiple times.
Yes, this is one advantage templates have

>Yes, obviously.
So if you work with a dynamic, not type safe language, and you write a completely not type safe function, but don't call it, the function is type safe?
>>
>>59514227
Post full code.
>>
>>59514197
Yeah, but you can see why that is haram. I think you need to while &mut slice.len or it's borrowed immutably for the entire block. I dunno, my rust is rusty.
>>
File: 7nTnr.png (67KB, 308x300px) Image search: [Google]
7nTnr.png
67KB, 308x300px
>>59514227
>==717== at 0x108A1B: main (main.c:43)
>(main.c:43)
Something tells me you didn't post the whole code.
How do you want us to help you if you don't post the whole shit, fagget
>>
>>59514133
So, ok, it's kinda getting tiresome.
The original point was "templates are faster and safer than void*". I've showed the first with actual evidence.
We kinda argued on the second only to discover you have your own idea of "type-safety, because "C's memory model does not feature types" thus everything is always magically safe even when you dereference void* as a wrong type, and type-safe language is one without type-checking errors. This is kinda pointless to argue further since we can't agree on the terms. I just want to cite wikipedia again
>In computer science, type safety is the extent to which a programming language discourages or prevents type errors. A type error is erroneous or undesirable program behaviour caused by a discrepancy between differing data types for the program's constants, variables, and methods (functions), e.g., treating an integer (int) as a floating-point number (float).
and to point out that templates prevent this kind of errors, while void* encourages them by erasing the type of value, and this is my original point.
>>
>>59514215
Got one that's loglogn. Instead of trial subtraction for each block, use a binary search.
>>
@59514127
learn programming slang, faggot
>>
>>59514286
>some TEMPLATE INSTANCES are safe,
All template instances are safe because unsafe ones can't be compiled.
>but TEMPLATES are not
Templates are a meta concept, what do you even mean by 'templates are not safe'?
>but don't call it, the function is type safe?
It's nothing if it's never called.
>>
>>59514318
>>59514290
struct node {
double value;
struct node* g;
struct node* d;
} node;

struct queue_node {
struct node* n;
struct queue_node* next;
} queue_node;

int main() {
struct queue_node* qqq;
(qqq) = malloc(sizeof(struct queue_node*));
(qqq)->next = NULL;
free(qqq);
return 0;
}

that's it
>>
>>59514326
>I've showed the first with actual evidence.
No, what you've showed is that giving the definition to the compiler allows for better optimisation and faster code.

Templates always give the definition, because of a flaw.
There used to be export templates, but only one compiler or something actually implemented it.

But as someone showed, clang can inline the argument to qsort and more.

>>59514326
The difference is who is deciding the types.
To a C programmer, an int is just a block of data with certain operations, and a float is also a block of data but with different operations.
When a C programmer casts the memory address of one to the memory address of another, they do so knowingly and intentionally, with the intent being to make use of the other set of operations.

Is this type safe? 2 / 3.f
Would you say that it's the programmer's fault?

>>59514377
You are saying that you can have code that's type safe "provided you don't call it"
This is nonsense. The code isn't safe.
You have to think about the (caps) C++ (caps) code, not the generated code (which probably doesn't use types anyway, depending)
>>
File: ox9ax99azw0y[1].jpg (54KB, 680x692px) Image search: [Google]
ox9ax99azw0y[1].jpg
54KB, 680x692px
Hey guys I'm trying to play with fstream header. I'm trying to read data from a file but instead of getting the next integer I'm getting some random negative number which is:
-858993460

Can you guys help me figure out the issue here?

code:
#include "stdafx.h"
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
int year1900, year1920, year1940, year1960, year1980, year2000;

ifstream inputFile;
inputFile.open("people.txt"); //open people.txt

inputFile >> year1900;
cout << year1900;

system("pause");
return 0;
}


txt file:
20000
30000
40000
50000
60000
>>
>>59514395
>sizeof(struct queue_node*));
That's the size of a pointer, not the struct.

To avoid mistakes like that I prefer the style of:

foo *x = malloc(sizeof *x);

Also robust if you wanna change foo.
>>
>>59514438
fug I'm stupid, thanks for the tip
>>
>>59514436
That doesn't make sense. A customs officer wouldn't let an illegal immigrant go just because he made a joke about hand game people play.
>>
>>59514424
>You are saying that you can have code that's type safe "provided you don't call it"
In the case of C++ templates, it's the case of "provided you don't compile it" which IS the definition of type safety - otherwise you have an infinite regress of ever more abstracted meta languages never being safe at the 'next level'.
>>
>>59514436
>not using if (inputFile)
>not checking the return value of inputFile >> year1900
you deserve this
>>
>>59514436
(with-open-file (s "people.txt")
(let ((year1900 (read-line s)))
(print year1900)))
>>
>>59514473
Templates can have syntax errors that break the entire file - but they're not part of the compilation process so it's not a syntax error
>>
>>59514453
You're autistic
>>
>>59514436
>int year1900
What?
>>
>>59514508
>he actually replied
>>
Hey guys, I was wondering, what are some of the methods used to collect variables and data from games and other programs into your own program?

Let's say I'm playing HearthStone, and I want to design a program that shows the cards I've played this game, and the remaining cards in my deck. How do you "hook" this data into your own program? Is there a certain widely used way of doing this or is this "hacks" that vary much from program to program? What language would be practical for this?

Thanks for any thoughts and input.
>>
>>59514537
>Hey guys, I was wondering, what are some of the methods used to collect variables and data from games and other programs into your own program?
Stop.
>>
File: how-to-approach-women[1].jpg (64KB, 1000x667px) Image search: [Google]
how-to-approach-women[1].jpg
64KB, 1000x667px
>>59514436
>>59514491
>>59514494
I got it. Simply had to save it in the proper folder. Duh I'm so retarded.
>>
>>59514537
You would hook onto the process using dll injection. Look for example how GWCA++ does it for guild wars. Note it takes quite some reverse engineering effort to find the correct variables.
>>
>>59514566
Thanks buddy, we have a starting point.

would +rep
>>
>>59514555
(mapcan 'list '(R T R) '(E A D))
>>
>>59514424
>But as someone showed, clang can inline the argument to qsort and more.
No it can't. It's been shown it can inline functions in a single TU, but qsort is never in your TU, and no one compiles C code in a single TU, except maybe sqlite.
> When a C programmer casts the memory address of one to the memory address of another, [..]
So, again, you invent your own definition of "type safety" and apply it to void*, while I'm talking about the generally accepted definition presented in the quote from wiki.
>>
give me some top tier patrician csci books. already got k&r, sicp and design patterns. looking for more than just languages, anything in the realm of csci. don't post "learning python for dummies" or other pleb shit
>>
>>59514615
I don't know what that means.
>>
>>59514620
Template codes also are in the same TU fampai
>>
>>59514537
Stuff like this is alwaysa hack, often bannable by game devs/mods
>>
>>59514656
CLRS
Learning Python for Dummies
>>
>>59514660
i suspect it's a reddity way of calling you a retard
>>
>>59514673
Sure but then they start installing rootkits to watch all your computer's processes to see if you're injecting shit. That's equally a hack and illegal (but then you agree to it).

RE stuff should be more widespread anyway.
>>
>>59514620
>...
This is because of a flaw in templates, and because of the header/source system.
A flaw in templates that means >>59514671
It is easier to optimise because it is less expressive.
*
There is an exception to this, which is when you are dealing directly with values, rather than pointers to them.
In which case it is useful (for performance and cache), and that obviously can't be runtime polymorphism without some awkwardness.

>So, again, you invent your own definition of "type safety" and apply it to void*, while I'm talking about the generally accepted definition presented in the quote from wiki.
I am saying that you and the C programmer are looking at the types differently.
The better way to express that you think C should be using types more distinctly and casting less obviously, i.e. that they should be using stronger types.
But the point I have made this entire time, is that it is casting that is not type safe, void pointers are perfectly type safe.
If you want the type system to make sure nobody touches your memory (within reason) without treating it as the same type you put in, then it's not type safe. But that's not what the C type system is about - the C type system is about everything directly translating to memory.
>>
>>59514620
>>59514709
And if you do go for templates, that are basically macros, it's better to do something like what D does, where you can give it any kind of argument, and it can make arbitrary declarations, rather than simply saying "it's generics"
>>
File: 1280.gif (295KB, 700x704px) Image search: [Google]
1280.gif
295KB, 700x704px
Why are you guys so nice to me?
>>
>>59514752
Fuck off, retard.
>>
>>59514702
Well what can ya do?
>>
>playing games that aren't open-source
>>
File: 1472936613088.jpg (49KB, 640x480px) Image search: [Google]
1472936613088.jpg
49KB, 640x480px
>>59514752
because you post lain
>>
>>59514777
>playing games at all
>>
>>59514774
The correct but painful and expensive answer is handle it server-side.
>>
what the fuck? how can you exclude .cpp source files (except the one you're currently editing) from content assist in eclipse? it should only show proposals from the included headers.
>>
>>59514817
>C++
>Eclipse
>>
Can I cast pointers to my custom struct types?
>>
>>59511906
>crunching

when my company expects me to crunch, I leave home 30 minutes earlierso I can have 30 more minutes to look for a new job
>>
>>59514799
>being alive
>>
>>59514833
yes
>>
>>59514832
suggest a better IDE with gcc support that can do what i'm asking then
>>
File: 19836136.png (265KB, 609x461px) Image search: [Google]
19836136.png
265KB, 609x461px
>>59514771
>>
>>59514537
In Hearthstone in particular this is legal as long as "you could do the same with pen and paper." Most deck trackers look at log files irrc.
>>
>>59514857
vim
>>
>>59514857
CLion
>>
>>59514855
So, if I have "custom" struct type, how do I access struct fields?
(custom)(pointer)->field = 123;

Like this?
>>
>>59514096
I have no Idea why this fixed it but now it works:
fn quicksort<T>(mut slice : &mut [T])
where T : std::cmp::PartialOrd + Copy
{
while slice.len() > 1 {
let old_slice = slice;
let (smaller_slice,greater_slice) = partition(old_slice);
quicksort(smaller_slice);
slice = greater_slice;
}
}
>>
>>59514885
>neckbeard text editor
lolno i'd rather use eclipse because it's literally better and i could probably make a plugin or something to fix this one tiny content assist flaw (you'd probably have to DIY or install a third-party plugin for vim anyway)

>>59514886
>€199.00 /1st year
>€159.00 /2nd year
>€119.00 /3rd yr onwards
kys
>>
>>59514709
> performance of templates
Well, I'm not gonna argue against templates being one big TU, I have to wait for them to compile every day. My point is still valid though - templates generally produce faster code, whatever the reason (and cost in slower compile times) is.
> If you want the type system to make sure nobody touches your memory (within reason) without treating it as the same type you put in, then it's not type safe. But that's not what the C type system is about.
I basically agree with you, but can you stop calling the void* approach (as in storage and USAGE, via casting and dereferencing) type safe? Because it's obviously isn't according to the generally accepted definition.
In this case I'm ready to modify my position to "Successfully instantiated template code is type safe, while code casting and dereferencing void* it is not".
>>
>>59514932
>i could probably make a plugin or something to fix this
>(you'd probably have to DIY
>>
>>59514967
yes?
>>
>>59514240
kys
>>
@59514977
see >>59514985
>>
>>59514896
((custom *)(pointer))->field
>>
>>59514684
my knowledge in programming is limited. I'd be more retarded if I came here pretended knowing more than what I do.
>>
>>59514963
Yes, in the sense that you care about the type that was put in when you take it out. Same for any other serialization.
>>
>>59515007
why are you telling me that
>>
>>59514932
Free for open source projects, why isn't your project open source?
>>
>>59514857
ve you tried netbeans senpai
>>
>>59515031
because you were listening.
>>
59515058
incorrect
>>
>>59514932
ur shit
>>
>working on android studio
>moving some classes between packages via good old drag and drop
>suddenly one class vanishes into thin air while I'm dragging it
>completely disappeared, not even a system-wide search can find it
>.class file is still there, .java file is gone
The file was already committed so I lost nothing, but what the actual fuck
>>
>>59515140
vim
>>
>>59514817
>>59515112
LOL i just had to put the source files in a separate folder and it's literally perfect now

linux neckbeards BTFO
>>
>>59515174
Fucking noob.
>>
Why do Java programmers use spaces instead of tabs?
>>
>>59514926
>>59514096
>adding two classes
WHAT THE FUCK
>>
>>59515322
Because they are noobs.
>>
>>59515322
The vast majority of Java programmers use IDEs that let you choose between soft tabs and hard tabs, so that statement is kind of pointless
Though I think all three major Java IDEs (Eclipse, Netbeans and Idea) use spaces in their default configuration
>>
>>59515322
>>59515390
>implying spaces aren't the superior indentation
Pajeets please
>>
>>59515375
Those are type traits
>>
Don't forget that golang would be the best language ever if it had generics
>>
>>59515396
>Though I think all three major Java IDEs (Eclipse, Netbeans and Idea) use spaces in their default configuration
doubt it

maybe many years ago but not now in the latest versions
>>
New thread:

>>59515417
>>59515417
>>59515417
>>
>>59513906
Sorry for the late response. I actually don't know much about any of it. I got some general JS experience but that's abkjt it for programming.

I was kind of wanting a book that would explain the fundamentals, concepts, and all that sort of thing. Preferably one with a ruby focus.
Thread posts: 314
Thread images: 22


[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.