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

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

Thread replies: 255
Thread images: 21
File: K&R c.png (1 MB, 1000x1400) Image search: [Google]
K&R c.png
1 MB, 1000x1400
old thread: >>54857016

What are you working on, /g/?
>>
>1 post early

Complete sudoku
>>
>>54864614
Reminder that mindless anti-JS shitters are as bad as pajeets.
>>
Learning me a F*
https://www.fstar-lang.org/tutorial/
>>
>>54864614
>Created before the bump limit
>Posting literal faggotry
Delete this shit and kill yourself.
>>
>>54864640
Lemma: OP -> Tot Faggot
>>
>>54864646
>making these posts
No, you kill yourself you autistic shitstain.
>>
Does anyone actually understand what urbit is trying to accomplish?

https://www.youtube.com/watch?v=I94qbWBGsDs
>>
>>54864659
functional OS

n.b.
functional does not imply functioning
>>
>>54864659

A post-singularity computing substrate
>>
>>54864659
oh damn
that's the guy who SJWs wanted to shut down
>>
I'm getting a "free(): invalid next size (fast)" error, randomally on a multithreaded program, which I can't replicate in valgrind (most likely because valgrind zeroes all the memory it uses for what you run on it). This is in normal C by the way.
Anyone knows a way to find the culprit fast? It's a very large file with many libraries. Something like 2k lines of code.
>>
File: qqqqq.jpg (127 KB, 500x500) Image search: [Google]
qqqqq.jpg
127 KB, 500x500
Why does everyone here seem to value learning another language instead of learning anything useful for a language they already know?
>>
>>54864659
holy shit look at the first slide he puts up

if that isn't bullshit I don't know what is

urbit is literally an open source joke, trying to get people hyped over what's actually LITERALLY fucking nothing.
>>
>>54864707
Useful people are put to use
>>
>>54864707
>language they already know
>>
>>54864707
Because they're autists that ""know"" 10 languages but can't program anything in any of them.
>>
File: dc6BMpxc9.gif (1 KB, 235x219) Image search: [Google]
dc6BMpxc9.gif
1 KB, 235x219
>>54864732
>implying writing Hello World in Haskell isn't knowing the language
>>
File: 3497046_300x300.jpg (19 KB, 300x300) Image search: [Google]
3497046_300x300.jpg
19 KB, 300x300
this is the Rust lead...
https://gist.github.com/steveklabnik/7cd3267a631c4847c34d
>>
>>54864753
Wait, haven't we seen him somewhere before?
https://www.youtube.com/watch?v=rRbY3TMUcgQ
>>
>>54864753
>I believe hate speech is violence.

Oh Klabnik, you complete fucking moron.
>>
>>54864753
What a filthy SJW. I don't mind his look and views, but bashing qt Yarvin is unforgivable.
>>
>>54864753
Is that aids skrillex?
>>
>>54864753
d-does he take h-hormones?
>>
any lambdaconf 2016 videos online?
>>
>>54864753
what a loser
>>
I wrote a proxy checker in python but it is complete shit, even after implementing threading.

Currently, I request a static page and if the text matches, the proxy works.

Is there a better way?
I've seen proxy checkers go though 10K proxies in 60~ seconds...
>>
>got a high-end laptop for a graduation present
>told my dad to hold onto it until I get a job so I stay motivated
>month in without a single job prospect
>hard drive fails
>"we had a deal anon!"
>>
>>54864659
what

also
>kelvin versioning
>decreases by integers to absolute zero
what
>>
>>54864958
get it fixed, might be under warranty or get another hard drive
>>
>>54864936
I check alexa most popular pages
>>
>>54864984
>what

It means that software is developed towards eternal stability. Urbit's ideal is a computing system that should remain unchanged for millenia because is works.
>>
>>54865053
it's retarded, it could be made more efficient and have features added to it, it's delusional to think you've reached perfection
>>
What are some sites other than Monster and Indeed for the job hunt? Preferably ones that have decent search algorithms (fuck Dice) and easy application features.

>>54865009
I'm going tomorrow but I'm also broke and he cut me off the day I graduated. I have one month's rent in the bank, plus maybe another in savings bonds
>>
>>54864936
You don't need to request a page to see if a proxy is alive.
>>
>>54865072
You can add features to apps that are built on urbit, but urbit's inrfastructure should be stable. Isn't it cool to have a bedrock abstraction over which everything works?
>>
>>54865265
Isn't that literally what a unix is?
>>
File: 1454240967157.jpg (31 KB, 456x320) Image search: [Google]
1454240967157.jpg
31 KB, 456x320
/g/, I cheated on an exam and I feel awful about it

I desperately needed an A in this class and shit wasn't going my way and I'd have ended up with a B if I had not. I could give a thousand of excuses but that's just running away from the sin.

How do I free myself from the guilt?
>>
>>54865357
Fess up and tell your professor.
You'll fail the course, and probably get kicked from the school, but at least you'll feel good about it.
>>
>>54865265
something can work just fine without have to use a pretentious label like "absolute zero" in a "kelvin versioning system"
>>
>>54865357
Just promise you'll never do it again, and learn to settle for Bs
>>
>>54865357
how do you even cheat on an exam

anyway desperate times call for desperate measures and it's no big deal in the end if you got an A instead of B
>>
>>54865325
Nah, unix is gigabytes of bloat at that point. Urbit is just 30k lines for the WHOLE SYSTEM from the turing machine to the OS.
>>
>>54865357
a small peek isn't cheating
unless you literally took his paper from his desk and copied it exactly
>>
>>54865357
Why did you need an A over a B? What class was it? The only way to free yourself is to apply yourself.
>>
>>54865095
?
>>
>>54865540
ping it
>>
>>54865540
Just open the connection in a work group. If the first packet is correct drop the connection and do another proxy.
>>
>>54865553
What if the proxy isn't working anymore but the host is alive?
>>
>>54865357
You gotta do what you gotta do to get ahead, this is the lesson you should take away. You're going to need to do a fuckton of worse things to get ahead or choose the pussy option and get nowhere, what do you want?
>>
If I open my job search to React, Angular and Backbone, am I just going to get a bunch of web design jobs?
>>
>>54865686
of course, what do you expect to get?
>>
>>54865695
to work on web applications or engines like they are made for
>>
File: Happy-Sad-Frog-25.jpg (70 KB, 400x388) Image search: [Google]
Happy-Sad-Frog-25.jpg
70 KB, 400x388
RUNNING TESTS: SIMPLE CALCULATOR (NO TOKENIZER)
ALL 107 TESTS PASSED @ TIME: 0.035s
RUNNING TESTS: SIMPLE CALCULATOR (USE TOKENIZER)
ALL 107 TESTS PASSED @ TIME: 0.016s
RUNNING TESTS: ADVANCED CALCULATOR (NO TOKENIZER)
ALL 107 TESTS PASSED @ TIME: 0.093s
RUNNING TESTS: ADVANCED CALCULATOR (USE TOKENIZER)
ALL 107 TESTS PASSED @ TIME: 0.039s
RUNNING TESTS: SYMBOLIC SIMPLIFICATION
ALL 56 TESTS PASSED @ TIME: 0.037s
RUNNING TESTS: SYMBOLIC DERIVATIVE
ALL 56 TESTS PASSED @ TIME: 0.063s
>>
>>54865695
I would expect it would be used for javascript that does something as opposed to using it for just animations and forms
>>
>>54865758
>I would expect it would be used for javascript that does something as opposed to using it for just animations and forms

Search for node.js then. Also unity has UnityScript which is derived from JS.
>>
>>54865771
I know it but most jobs want angular and I'm running low on options. after this month I'm out of rent money and I'm to unsightly to be a stripper
>>
>>54865945
node js is super popular, I don't see how you can't find job with it.
>>
>>54866081
Everyone in new york is still using rails, django and java
>>
>>54866194
go frontend then, its not bad
>>
Is it good practice to declare unsigned types with their size like say
u_int32
compared to say int?

Isn't explicit a good practice for portable code that way you don't have to deal with different compilers making their own assumptions and stuff like say the default size of int on one machine is 32 bits and 64 on another??
>>
File: 1463051103089.jpg (36 KB, 640x480) Image search: [Google]
1463051103089.jpg
36 KB, 640x480
>>54865380
>>
>>54865448
hell, unix was bloated before it was even released
http://lists.busybox.net/pipermail/busybox/2010-December/074114.html
>>
>>54865357
alcohol and other drugs
>>
>>54864753
I thought people who wrote system level programming langauges were cool
>>
>>54865357
>How do I free myself from the guilt?
earn your next A
>>
>>54866281
>Is it good practice to declare unsigned types with their size like say u_int32 compared to say int?
There's a header that contains macros for exactly this. stdint.h
it's good practice because it improves portability. I'm not aware of any cons.
>>
>>54864753
>lead

All he is is the "developer advocate" for Mozilla w.r.t to Rust. He writes friendly documentation and shills Rust around the internet and the convention space. (would you expect anything more from a ruby/rails fag?)
>>
Class project, need to implement AIMD over a udp connection.

Have any of you guys had experience with python sockets? I'm trying to send a file over udp (i know that it's lossy) and if a packet gets dropped i want to know so i can reduce the rate at which they are sent.

However the first packet passes but the others just fail and the conenction is terminated. Any tips? Also newfag here, not sure how to post code. Sorry if I'm being a bother I just really need help
>>
>>54866611
>it's good practice because it improves portability. I'm not aware of any cons.
Actually, it reduces portability, as the (u)intN_t are optional types. Your code will no longer work in situations where those types don't exist, but it is pretty damn rare to find an implementation where they don't.
Also, the types themselves add some possibly misleading information.
If you're using "for (int32_t i = 0; i < n; ++i)" instead of something like "for (int i = 0; i < n; ++i)", you're implying that 'i' HAS to be 32 bits for some specific reason.
>>
trying to teach myself Java before taking classes this fall. i'm trying to make a bill counter (no coins yet) but when i run the program, it asks the first question, i type my answer, and it prints the answer (in the first case times 100) but then sits there, and does not advance to the next question until i type in the number a second time.

any idea what gives? sorry i'm bad at explaining.

import java.util.Scanner;

public class BillCounter {
public static void main(String[] args){

int hundreds, fifties, twenties, tens, fives, ones;

System.out.println("How many hundreds?");
Scanner hundredCount = new Scanner(System.in);
System.out.println(hundredCount.nextInt() * 100);
hundreds = (hundredCount.nextInt() * 100);


System.out.println("How many fifties?");
Scanner fiftyCount = new Scanner(System.in);
System.out.println(fiftyCount.nextInt() * 50);
fifties = (fiftyCount.nextInt() * 50);


System.out.println("How many twenties?");
Scanner twentyCount = new Scanner(System.in);
System.out.println(twentyCount.nextInt() * 20);
twenties = (twentyCount.nextInt() * 20);

System.out.println("How many tens?");
Scanner tenCount = new Scanner(System.in);
System.out.println(tenCount.nextInt() * 10);
tens = (tenCount.nextInt() * 10);

System.out.println("How many fives?");
Scanner fiveCount = new Scanner(System.in);
System.out.println(fiveCount.nextInt() * 5);
fives = (fiveCount.nextInt() * 5);

System.out.println("How many ones?");
Scanner oneCount = new Scanner(System.in);
System.out.println(oneCount.nextInt());
ones = (oneCount.nextInt());

System.out.println(hundreds + fifties + twenties + tens + fives + ones);

}
}
>>
>>54867146
> UDP
> The connection is terminated

You do know that UDP is connectionless, right?
>>
>>54867144
still probably makes more than any of us tee bee hech
>>
>>54867146
post ur code
[ code ] and [ / code ] without the spaces of course
>>
>>54867178
or preferring to use size_t / std::size_t
>>
>>54867221
reuse the scanner;
Scanner in = new Scanner(System.in)
println("Hundreds")
count+= in.nextInt()*100
println("50s")
count+= in.nextInt()*50
//etc
>>
>>54867221
hint: why are you remaking the scanner each time?
>>
>>54867221
>>54867246
Basically the Scanner will eat up as much input as it can, so the 2nd scanner doesn't get it because the first on ate it already, even though it did not need it for the nextInt() call.
>>
>>54867233
The client meat

with open(filepath, 'rb') as f:
data = f.read(BUFFER_SIZE)
while data:
if s.sendto(data, (HOST, PORT)):
chunks += 1

try:
# wait for reply from the server, max 1024 bytes
ack, addr = s.recvfrom(BUFFER_SIZE)
if ack == 'ok':
print "accept"
wait -= 0.00001
except socket.timeout:
print "fail"
wait*=2


data = f.read(BUFFER_SIZE)
time.sleep(wait)


The server

while True:

data, addr = s.recvfrom(BUFFER_SIZE)

if data == "-1":
s.sendto("ok", addr)
else:
with open("test.txt", 'wb') as f:

while(data):
if data == "-1":
continue
else:
print "Receiving File ..."
f.write(data)

# Send ack to client
s.sendto("ok", addr)

data, addr = s.recvfrom(BUFFER_SIZE)
s.close()
>>
>>54867178
>If you're using "for (int32_t i = 0; i < n; ++i)" instead of something like "for (int i = 0; i < n; ++i)", you're implying that 'i' HAS to be 32 bits for some specific reason.
And with int you're implying i HAS to be log2(INT_MAX) bits for some specific reason.
>>
>>54867246
fffuuuuckk
ok cool thank you so much.
>>
>>54867276
ok that makes sense. that's why when i googled, people were saying to close the scanner, but that didn't seem to be working for me.
>>
>>54867305
Your implying it has to be:
a) signed
b) no decimals
c) for any positive integer n, log2(n)=2^n

You are implying nothing about the size, which is implementation defined.
>>
Well, my compiler can now produce valid programs that assign values to variables* in memory. It can also generate procedures and if statements and such. It cannot call procedures yet, so I can't print anything to test if it's valid or not. That shall be done tomorrow.

* can't do arrays yet. Might not do arrays if I don't have the time.
>>
>>54867360
>statements

>non-expression based language

You make me sick you son of a bitch.
>>
>>54867144
http://blog.rust-lang.org/2014/12/12/Core-Team.html

still part of the core team
>>
how do i delete only one character from my entry?
self.entry.delete(first=0, last=END)
this deletes all
self.entry.delete(first=END, last=0)
this does nothing.
>>
>>54867363

Err... it has expressions and statements. I can handle all expressions except function calls, and all statements except procedure calls. I don't have a choice over the language. It's actually a rather ugly sorta Pacal-like language... with a few oddities the professor added (he took most of it from another professor at another university), namely nested comments and the use of <-- as an assignment operator.
>>
>>54867367
writing documentation is important. but language design and direction is barely dictated by it or its package manager (in the case of katz). especially when cargo is literally a copy of bundler.

but Mozilla has been a SJW shitfest since the tumblerinas forced Eich out of the CEO position.
>>
>>54867392
whoops. im retarded. cant into [code/]

self.entry.delete(first=0, last=END) ##this deletes all.

self.entry.delete(first=END, last=0) ##this deletes nothing
>>
>>54867395
>it has statements
Exactly you twisted fucking pervert
What fucking abomination have you brought into this world?
>>
>>54867281
The issue I'm having is that the first chunk of data goes though but all the other chunks are not received by the server.
>>
>>54867428

I did not invent the language.

Anyways, this is the program I'm able to actually compile:

program ATest;
variable a, b : integer;
variable c : boolean;
begin
a <-- 5;
b <-- a + 3;
c <-- true;
end ATest.


And the end result code looks like this:

        call 0, ATest$0
halt
L$$errornoreturn: load 0, L$$globalstring
movs "ERROR: function did not return."
pint 0
csp wrs
csp wln
halt
ATest$0: pint 3
adds
pint 5
stor 0, 3
load 0, 3
pint 3
add
stor 0, 2
pfal
stor 0, 1
exit 0, 0
L$$globalstring: .bss 32


Note: in theory, I don't need to generate the errornoreturn procedure if I don't have any functions. In practice, I'm just going to generate it anyways since I can't be fucked to introduce yet another global variable to this already disgusting mess of a compiler.
>>
>>54867476
Why the fuck didn't you invent the language?
>>
>>54867476

And I just realized I had a slight bug. Was pushing false onto the stack where I should have been pushing true. Similarly, program pushes true when it should push false. All because I forgot the ! in front of a strcmp check. Derp.
>>
>>54867492

This is a class assignment. Professor hands us a spec, we build to the spec. One does not deviate from the spec.
>>
>>54867523
Tell your professor that statement based languages are retarded
>>
>>54867476
>end.

only Pascal-like (ones designed or influenced by Wirth) languages do this. PL/I, Ada. Fortran, Algol, Simula, etc don't use a period after the final end.

so.. what language is it? I don't recognize <-- for assignment. Modula2, Oberon, Pascal, Delphi, Ada, PL/I, etc use := for assignment. OCaml, S, R, etc use a single arrow for assignment (sometimes you can even do a right-arrow in S+ and R (42 -> a)). But not one with a double hypen / emdash / whatever.
>>
I'm going to learn Haskell... Is that a good idea?
>>
>>54867633
Yes
>>
>>54867633
Yes. Using it for something serious, however, isn't.
>>
>>54864614
Is the C book in OP actually good for learning or is it like learning english from the dictionary?
>>
>used C++ and some other higher level languages all my life
>started using C for necessity
>hated it at first
>now I like it

What the fuck is wrong with me? I'm not even bothered by the clumsy string manipulation at all.
>>
I've been programming small scripts to just automate small annoyances for years but never really got good at programming.

Is there a set of books that will give me a good foundation in mathematics and algorithms as well as just general programming in order to use as a jumping off point?
>>
>>54867738
It's definitely a tutorial book, not a reference trash text like most 1000+ page programming textbooks today.

It fully assumes that you know how to program, tho.
>>
>>54867738
its a reference but a good one, like a set of wikipedia articles that are authorative and on-point. It doesn't give you tutorials or such, so its more of a reference companion when you need to know what the real definition of what is going is.
>>
>>54867807
Yes
>>
>>54867841
>it's a tutorial, not a reference
>>54867837
>it's a reference, not a tutorial
>>
>>54867738
It's great dude, has walked exercises and p sets plus he doesn't introduce new stuff without a previous explanation
>>
>>54867854
>>54867841
>>54867738
Its a reference of meme tutorials.
>>
>>54867854
The guy saying it's a reference book is probably used to baby tier hand holding tutorials.
>>
>>54867869
It's not a reference it's just a few pointers
>>
Man I've been code reviewing other people's C++11 bullshit the entire day and if I see one more template of a template specialized on some esoterica that takes a parameter pack that returns a decltype of an argument I'm going to literally shove paperclips into my eyes so I can call in sick tomorrow. Yes I get it it works and for fuck sake its necessary if you want to write generic algos but at what point do you differentiate template metaprogramming from run-of-the-mill masochism.
>>
>>54867905
Switch to a newer compiler
Less decltype more auto
>>
>>54864700
You're clobbering part of your heap allocator's memory space. Check for use after free / unit cases. If it's not replicated in valgrind then it's either a thread synchronization issue, or equally likely that it's a small access to unint memory as valgind pads the shit out of allocated memory chunks.
>>
>>54867854
>>54867869
>>54867876
>>54867877

I'm the guy who said its a reference. Honestly its been about 5 years since I looked at it so I guess I'm just misremembering it. I had already learned C by that point and used it mostly as a reference, and it worked well in that regard. Maybe it had tutorials n shit I just never used.
>>
>>54867942
It's a tutorial.
The appendix is basically a summary of the C89 standard and the standard library, and I guess you could call it a reference text of sorts.
>>
>>54867935
>unit cases

un-init*
>>
>>54867549
He's a fan of Pascal. What problem do you have with statement based languages?

>>54867609
The language is called ATL/1 (ATL = A Teaching Language). It's a made up language that exists only for the sake of getting us to make a compiler in 8 weeks.

>>54867759
C's not that bad when you get into the hang of it.
>>
>>54867905
the most cancerous language
>>
I'm reversing a 50k ARM proprietary binary blob (for learning purposes©).

I had to settle for running IDA in wine since I couldn't find a recent version that had a feature I was interested in.

Anyway, I did a big mistake, I loaded the binary in a ROM segment instead of a RAM segment.

This makes IDA automatically constant-fold things, and yell warnings when the instructions are writing something in ROM.

Any idea how I can change the properties of a segment?
I've looked everywhere...
>>
Design and Analysis of Algorithm

Time:3hours
Total marks:90

Q1. Attempt any four questions:
a.what do you mean by analysis of Algorithm. Write algorithm for binary and linear search.

b. Analyse the merge sort algorithm. Argue on best case, average case and best case time complexity.

c.show how to sort n integers in the range 0 to (n^2-1). In O(n) time.

d.solve the recurrence relation T(n)=4T(n/2)+n^2 by recursion tree.

e. Write short note on Asymptotic notations. Find Big Oh(O) and Big Theta notation for f(n)=27n^2+16n+3.

f. A=(15,23,13,2,1,25). illustrate the operation of Heap-sort on A.


Q2. Attempt any four questions:
5×4
a.Explain the properties of B-tree. Insert keys F,S,Q,K,C,L,H,T,V,W,M,R,N,P,AB Into an empty B-tree of order 5.

b.construct a RB-tree of insertion and deletion with example and its properties and algorithm

c. Explain the process of Augmenting Data Structure with example.

d. Prove that that the maximum degree of any node in n-node binomial tree is logn.

e. Prove that red black tree with n internal nodes has height atmost 2log(n+1).

f. Explain the properties of Binomial Heap and Fibonacci Heap with example.


Q3. Attempt any two questions:
10×2
a. Determine the LCS of (1,0,0,1,0,1,0,1) and (0,1,0,1,1,0,1,1,0).

b.what is optimal Huffman Code for the following set of frequency as:
a-1,b-1,c-2,d-3,e-5,f-8, g13,h-21.

c. Compare greedy versus dynamic programming. Prove that the fractional knapsack problem has the greedy choice property.


Q4. Attempt any three questions:
10×2
a. Compare BFS and DFS. Explain why solution does not find using Bellman Ford algorithm if there is a negative weight cycle that is reachable from the source.

b. What is meant by strongly connected components. How can the number of strongly connected components of a graph change if a new edge is added.

d. What is string matching problem. Describe the procedure of Rabin Karp Algorithm when T=314692653589793 when p=26 and q=11.so how many supurious hit.
>>
>>54865357
learn your lesson, dont cheat again and move on
confessing will do you absolutely zero good at this point
>>
>>54867837
>It fully assumes that you know how to program, tho.
What if I don't know. Is there a newb book for C?
>>
Is an algorithm recursive when it uses an output as an input to itself?
Just got back some marks and apparently I used iteration instead of recursion so I'm baffled as to how a recursive function is anything but what I just wrote.
>>
>>54869089
You probably wont listen to me, but, learn to program in a higher level language, otherwise you will probably get bored and do something else. Even if its not a 'good' language you can get something done and learn basic program structure. I recommend something like JavaScript, Python, AutoIt, etc. They all will let you deal with real problems, rather than battle with the C stdlib for basic string manipulation.
>>
>>54869098
i don't quite get your output/input thing, but a recursive function is one which calls itself. Its passing intermediate data (not what it returns, if that's what you are calling output) to itself.
>>
>>54869089
I recommend Programming in C by Kochan, it reasonably goes through introductory topics and also explains C while it's at it.
>>
Get moved off the Web API project because waiting for the mobile app developer to catch up. Got put onto a browser-based web application instead. Cool, haven't used JavaScript in a while.

What a fucking mess. It's like someone suffering from schizophrenia designed a "programming" language.
>>
>>54869098
int recursive_factorial(int n){
if(n<=1) return 1;
return recursive_factorial(n-1)*n
}
int iterative_factorial(int n){
int acc=1;
for(int i=2; i<n;i++){
acc*=i
}
return acc;
}
>>
>>54869120
This. But if you do need to do something that requires lower level like gamesev, go back to C or C++, but after a higher level language
>>
>>54869327
I like js, it does what it does best, makes it easy to make frameworks, and has some fun ones floating around. Plus the recent speed is a bonus
>>
>>54869327
>What a fucking mess. It's like someone suffering from schizophrenia designed a "programming" language.
Well, it was made by Brendan Eich, a fucking white male homophobe, that wanted a Scheme with C syntax, so I guess you are correct.....
>>
>What are you working on, /g/?
https://github.com/enfiskutensykkel/bf-compiler

Made some improvements to my Brainfuck compiler. Will look at more optimisations later on.

I'm also considering making write and read as functions and just do call in order to avoid replicating the syscall boostrapping over and over again.
>>
>>54869446
Also, if any one knows what's faster of the two following on x86, please let me know

movb (%rbp, %rdx), %al
addb $<some constant>, %al
movb %al, (%rbp, %rdx)


vs

addb $<some constant>, (%rbp, %rdx)
>>
How do I construct a recursive function?
>>
>>54869562
int func(...)
{
return func(...);
>>
>>54869573
but how do you get it to stop?
>>
>>54869589
By having multiple return statements.
>>
>>54869589
int factorial(int n)
{
if (n == 0)
return 1;

return n * factorial(n - 1);
}
>>
>>54867837
Not the guy that you replied to but I'm pretty gud with c++ I'm working with c#.
By my knowledge of cpp I obviously know some C but I wouldnt call it an industry level by any means.
Would that book be good for me? I don't need explanation what for is, or what a pointer is, or what malloc is. But reasonable examples and libraries usage + some C tricks that are not so natural in other language (void* manipulations etc?)
>>
File: 1464776646043.png (126 KB, 280x280) Image search: [Google]
1464776646043.png
126 KB, 280x280
>my country only offers bachelor degrees in computer engineering, not CS or software engineering
fugg
i dont really like electronics and shit
>>
>>54869876
What is your country?
>>
File: 1463855604565.jpg (32 KB, 405x437) Image search: [Google]
1463855604565.jpg
32 KB, 405x437
My very first self-written program.

//calculates sales tax

#include <stdio.h>

#define FINAL_AMOUNT (dollar_amount * tax) + dollar_amount

int main (void)
{
float tax, dollar_amount, final_amount;

printf ("Enter dollar amount: ");
scanf ("%f", &dollar_amount);
printf ("Enter tax percentage in decimals: ");
scanf ("%f", &tax);
final_amount = (dollar_amount * tax) + dollar_amount;
printf ("With tax, that is %.2f.\n", FINAL_AMOUNT);
return (0);
}
>>
>>54869635
ah, i see
>>
>>54869904
sweden
>inb4 cuck, jamal and mudslimes
you people should stop getting your news from /pol/
>>
>>54869911
Forgot to edit out old code

>
//calculates sales tax

#include <stdio.h>

#define FINAL_AMOUNT (dollar_amount * tax) + dollar_amount

int main (void)
{
float tax, dollar_amount;

printf ("Enter dollar amount: ");
scanf ("%f", &dollar_amount);
printf ("Enter tax percentage in decimals: ");
scanf ("%f", &tax);
printf ("With tax, that is %.2f.\n", FINAL_AMOUNT);
return (0);
}
>>
>>54869935
Easy there abdul.
It's /dpt
>>
>>54869935
Dere har computer science da, din ultrajode.

It's just slapped together with computer engineering too, but that's how it is in Norway.
>>
>>54869944
there's no need for that macro
>>
>>54869996

I couldn't get it to work as a float. What did I do wrong?
>>
>>54870009
What do you mean you couldn't get it to work?

printf ("With tax, that is %.2f.\n", dollar_amount * tax + dollar_amount);

Just werks, there's no need for parentheses either, because of operator *'s precendence.
>>
>>54870042

Oh, I didn't realize I could declare a float within the string. Thanks, you just saved me a lot of headache. I've only been at this for a couple days.
>>
>>54870054
Oh, happy to help.
>>
>>54864697
story pls
>>
>>54870054
Keep at it, bud
>>
>>54869120
>>54869249
thanks
>>
#include <cstdlibh>

// comparisonless max function
int max(int a, int b) {
try {
1/(a - b - std::abs(a - b));
} catch (...) {
return a;
}
return b;
}
>>
>>54870187
And yet slower.
>>
Say I have a branch in my code, example if my program were to detect the presence of SSE and choose an SSE optimized code path, and that branch is taken 100% of the run time, will branch prediction completely or almost nullify any overhead of a branch? if not, what kind of overhead and is it worth replacing with a pre-compiler branch?
>>
>>54870187
ARITHMETIC OVERFLOW FOR SIGNED INTEGERS IS UNDEFINED BEHAVIOUR
>>
Googled around, can't readily find an answer.

In C++, how do I read a file in integers rather than bytes? I tried making an array buffer and then static_cast-ing it to another type, but it wouldn't compile. I'm thinking about this on a bit level, ie, why can't I just read in multiple bytes and concatenate them?

I can't figure out how to alter things once they're considered to be in an array in a given form.
>>
>>54870282
FILE* file = fopen("filename", "r");
int integer;
fread(&integer, sizeof(int), 1, file);
>>
>>54870300
I'll have to read about fread then. I was doing:
char buffer[4];
file >> setw(4) >> buffer;
//The data is now available in an unnecessarily inconvenient form
//stuff
>>
>>54870328
What happens when you try to open that file on a Motorola with a different endianness to x86? Directly storing integers is bad mmkay.
>>
>>54870328
I never liked C++'s IO streams. A lot of stuff in the stdlib makes sense, but the IO stream stuff is just impractical AF.
>>
>>54870328

>>54870300 is a C solution, you can do this in C++:

std::ifstream is {"Input.txt"};
int i;

while (is >> i)
{
std::cout << i;
}
>>
>>54870358
There are plenty of standard library functions to handle endianess.
>>
hey i have a file that looks like this

`
123:123:123:123:123:123
abc:abc:abc:abc:abc:abc
456:456:456:456:456:456
'
with newlines on the end of each line.
I would like to print the first characters before the ":" delimiter from all sets like:
`
123 abc 456
123 abc 456
' etc

what do?
>>
>>54870358
Portability is secondary to performance / actually functioning at all, right now. As long as it compiles for all major OS's, assuming little endian is probably fine enough...

Not like I can do much of anything anyway. Barely know enough to generate code that works, much less code that'd be considered production quality.
>>
>>54870218
It will take an entry in the branch table.
You might want to make it so this branch is evaluated as few as possible.
Possibly only once.
>>
>>54870399
for line in open("filename.txt").readlines():
chars = {}
for key in line.split(":"):
chars[key] = True
print " ".join(chars.keys())
>>
>>54870399
awk
>>
>>54870363
I'd assumed this would just overflow? What signals it to stop reading from the stream?
>>
>>54870464
0 stored in the file
>>
>>54870464
in C, if you assign in an eval (), it will eval to true if NOT 0
which is why people check null with (!ptr)
>>
>>54870499
So if you're trying to read the number 0, it will stop?
>>
>>54870464
It stops at the end of file, you can rephrase it to:

while (!is.eof()) {
is >> i;
}


if you want.
>>
>>54870479
I'm trying to seek around and read arbitrary parts of a file (eg parsing a header), not read to eof.

Would this work if parts of a file were delimited by null bytes, or is it somehow keyed only to the end? Is it not reading the contents of the file, but the stream position pointer?
>>
>>54870438
is this python?
>>54870459
awk?
>>
Job interview in 2 1/2 hours, hope I don't fuck it up.
>>
>>54870553
God spede anon
>>
>>54870095
he trolls them online anon and they doxxed him
>>
>>54867335
>for any positive integer n, log2(n)=2^n
Fo shizzle, ma nizzle?
>>
>>54870360
Yeah I agree, if I expect to be using file I/O I try to avoid using C++ if I can
>>
>>54870739
What's wrong with streams?
>>
>>54870479
Yo dumb,
is >> n
evaluates to is, not n

>>54870537 they are dead wrong, such code doesn't stop when it reads a zero. In addition, this input method PARSES an int out of decimal digits, it doesn't let you access the raw bits AT ALL
>>
File: fire.png (765 KB, 698x840) Image search: [Google]
fire.png
765 KB, 698x840
>>54864614
Looking for a good scripting language which is easy to embed, has a JIT which covers at least x86 and arm, and works properly in a 64bit memory space. So far i'm struggling.
>>
>>54870787
No matter how much documentation I look through, when it comes to implementing anything it seems like I'm just fucking around with a black box. The outputs are predictable to an extent, but I'm just repeatedly making errors and iterating.

I've got the general structure of an entire program planned out in my head. There'll probably be some changes, but fuck if I can implement any of it. System seems mechanical in the wrong way for me.

Oh well. I'll get it eventually.
>>
>>54865722
what are we doing here
>>
>>54870782
Over-engineered approach to IO, increasing the amount of code required to do I/O rather than reducing it.
>>
>>54870787
What's the point then? Anon specifically wanted to deal with raw data.
>>
>>54871020
So, theoretically it's better if I just put together my own wrapper over FILE*?
>>
>>54870843
Neat. My argument parser now works properly, and checks that specified inputs actually exist, in the main loop. Stores the file handle in a vector of structs along with the file type, and passes it by reference accordingly.

I made something that works.
>>
>>54870843
Not my problem
>>54871042
The point in what?
>>
Disgusting & useless hack of the day:

db 0x50, 0xEB, 0x03, 0xE9
dw isCode16-$-2
db 0x35, 0x00, 0x00, 0xEB, 0xF8, 0x58
isCode32:
; ...

isCode16:
; ...


Detect whether your code is running on a 32bit or 16bit x86 CPU, and run different things in response! Portable machine code!
>>
>>54871081
>Not my problem
Never implied it was. I appreciate any feedback, but ultimately I'll ramble on as I see fit and there isn't much a given recipient can do about it.

ie, no need to be a dickhead.
>>
Bikeshedding: the thread

Just like every dpt since a few years. Why do you fucks even bother any more
>>
>>54871105
>What I Do Is Pointless And I'm Proud Of It: The Post
Who's the dickhead again?
>>
File: hereToHaveFun.png (11 KB, 935x729) Image search: [Google]
hereToHaveFun.png
11 KB, 935x729
>>54871164
>>
>>54871202
It has an inherent purpose, but not necessarily for you.
>>
>>54871065
Yes.

But boost already does this. Use boost.
>>
File: vomit.jpg (90 KB, 650x650) Image search: [Google]
vomit.jpg
90 KB, 650x650
>>54871253
>Use boost
Using C++ alone is bad enough, but holy shit.
>>
Can anyone please post the challenges?
>>
File: 1461713379623.png (378 KB, 1450x1080) Image search: [Google]
1461713379623.png
378 KB, 1450x1080
>>54871291
>>
>>54871253
But boost looks just as bad if not worse, Anon. :c
>>
>>54871281
>>54871316
Stop memeing. Boost is sepples done right.
>>
>>54871342
You should seriously consider suicide.
>>
Long live Hime in the OP!
>>
>>54871588
Good summary.

However, I don't think anyone would be surprised by anything in this post.
>>
>>54871303
ROLL for my free time at work

Anyone else here actually employed in the field? Java dev here
>>
File: gkis.webm (2 MB, 889x500) Image search: [Google]
gkis.webm
2 MB, 889x500
/dpt/-chan, daisuki~

>>54870838
http://codelle.com/blog/2016/5/embedding-pypy-in-a-c-application/

>>54869462
second for obvious reasons.

>>54865357
>How do I free myself from the guilt?
By doing your walk of atonement

>>54864753
This is what happen to you when you program at low level and mess your pointers.

>>54864659
>functional assembly language
You first need a functional ISA for that.
>>
>>54871588
literally who gives a shit
>>
>>54871673
Reroll

>>54871682
Fucking this
>>
Ive been doing a few small standalone sites in my free time, does anyone know if a good UI resource to begin learning? I suck ass at making an alright design
>>
>>54871372
>le kill yourself meme
If you hate the C++ way of doing things, why use C++ at all? I don't get it, it's like using Haskell and complain that it isn't anything like Visual Basic.
>>
>>54871720
>If you hate the C++ way of doing things, why use C++ at all?
I think C++ is awful.
But using boost is like puking on a pile of shit.
>>
>>54871644
Personally I'm surprised by the length. I was waiting for

>They have just completed the 29,000th episode.
>>
>>54871080
And I'm back to nonsensical problems. I use the read function to read in 4 bytes from the start of the file. I'm looking at this file in a hex editor, the first byte is decimal 137. Casting the inputs to an int gives -119, and all the other checks fail.

Why is it reading in bytes if it won't let me read into unsigned types. Why must it overflow.
>>
>>54871732
Boost is C++ done right. There's a reason why 11, 14 and 17 all draw heavily from boost.

But I guess you hate the fact that C++ is drawing more and more functional concepts.
>>
>>54871677
Source on cute yuri.

Are there any almost universal GUI frameworks?

Something that would run on tablet, desktop, phone, and console.
>>
>>54871754
Little endian anon. Little endian.
>>
>>54871787
>functional concepts
what
the only thing that sets boost apart from other libraries is extensive (and proper) use of templates
>>
>>54871811
Boost optional, for example, is an implementation of maybe. It's just one of many examples.
>>
File: when_anime_eat_pizza.webm (3 MB, 800x450) Image search: [Google]
when_anime_eat_pizza.webm
3 MB, 800x450
>>54871794
Yes, imgui.

https://github.com/ocornut/imgui

>>54871794
>Source on cute yuri.
https://www.youtube.com/watch?v=2qwDR2ONVuM
>>
>>54871806
I don't get it. Regardless of endianness, it shouldn't be returning negative values.

PNG defines byte order as being little endian either way, nothing should be stored on disk big endian. And when I think of eg 254 stored in memory it's 11111110. What the hell is its problem? Give me my fucking bytes.
>>
>>54866281
Only when you need them to be that size.

int is usually the processor's word size, so it's what you should be using for numbers that you know that won't go beyond 16 bits signed
>>
>>54871887
Also, why the hell would bytes be read in as signed? That's ridiculous.
>>
>>54871882
>imgui

The thought of doing GUI in C++ gives me cervical cancer.

Also, it looks like shit, but I suppose that's up to the designer.

Thanks anyway.
>>
>>54871887
254 is stored in memory as
FE 00 00 00 (depending on the data type)
>>
>>54871913
Int is signed ffs
>>
>>54871933
>FE
Right, 11111110. With some padding, because 4 byte clusters.
>>
>>54871932
>The thought of doing GUI in C++ gives me cervical cancer.
https://github.com/ocornut/imgui/wiki/Links

>>54871932
>Also, it looks like shit, but I suppose that's up to the designer.
It's really powerful and easy to use. you are free to customize the look.
>>
>>54871992
I played Counter Strike for nearly a decade.

I can't anymore because of this.
>>
>>54871945
I'm getting irrationally angry here. Your post doesn't even make sense.

Fucking hell, I'm going manage to process these 4 goddamn bytes the fucking way I want to, or kill myself. I have had enough.
>>
>>54872006
I don't understand how you are unable to read four bytes into an int. Post code please.
>>
File: anime_eat_burgers.webm (3 MB, 1280x720) Image search: [Google]
anime_eat_burgers.webm
3 MB, 1280x720
>>54872000
lel, wait for when cheaters find out that there no protection at all on steamos/linux.
>>
>>54872038
>no protection at all on steamos/linux
As in, VAC doesn't monitor those systems?

You know, I never thought about that.

Not only would gamedevs have to design to be compatible with all of the special snowflake Linux distros, they'd also have to be able to design their anti-cheat measures to work globally, which would be...impossible.
>>
>>54872036
I have temporarily given up on the notion of reading into anything other than an array of chars, which are obviously signed and therefore fucking up everything. Anything else fails to compile.

{
char id[4];
png.read(id, 4);
std::cout << static_cast<int>(id[0]) << "\n";
if (!(id[0] == 137 && id[1] == 80 && id[2] == 78 && id[3] == 71))
std:: cout << "Not a png.";
}
>>
File: 1408751367381.jpg (2 MB, 3504x2336) Image search: [Google]
1408751367381.jpg
2 MB, 3504x2336
>>54872049
>As in, VAC doesn't monitor those systems?
No and you know why ? VAC needs to be executed in the kernel to be able to monitor for ring0 cheats, but on linux, anything running in the kernel must be open source because of the gplv2. Thank you richard m. stallman (PhD).
>>
>>54872086
Great, the shitty GPL license manages to yet again be unnecessarily restrictive.
>>
In C++:
Tabs or spaces?

If tabs, how long (4, 8)?
>>
>>54872108
tabs (2-4) for indentation, spaces for alignment
>>
Is there any visual studio addon that will highlight doxygen tags?
>>
>>54872130
>he fell for the tabs meme
Sane people use spaces and break lines at 79 characters.
>>
>>54872070
#include <stdio.h>
#include <stdint.h>

struct anon {
union {
uint32_t i;
uint8_t c[4];
};
};

int main(){
struct anon a;
a.i = 3458934;
printf("%X %X %X %X\n", a.c[0], a.c[1], a.c[2], a.c[3]);
return 0;
}


:3
>>
>>54872086
>No and you know why ? VAC needs to be executed in the kernel to be able to monitor for ring0 cheat
VAC's ring0 module is no longer in use, and hasn't been in a long time
>>
>>54872136
>struct anon {
>union {
Or, you know:
union anon {
>>
>>54872049
>>54872086
>>54872038
more importantly, cock.li's cheat isn't working for 64bit (yet)

valve forced csgo on linux to be 64bit

but yea steamOS is cheat heaven
>>
>>54872167
yes, you could also customize an open source graphic driver like mesa3d to implement graphic cheats.
>>
>>54872136
The read function will only read to char.

I've made it work by casting to a temporary unsigned char, then casting that to an int (would probably work the same just using it directly). For some reason casting the array variable just yields the same result.

That doesn't even make sense. My brain seeming isn't working properly. I just gotta go.

Fuck it all.
>>
>>54872070
>I have temporarily given up on the notion of reading into anything other than an array of chars, which are obviously signed and therefore fucking up everything. Anything else fails to compile.
You're doing it wrong ffs.
>>
What kind of hardware would you use to sense water on a windshield?

What language is automotive software usually written in?
>>
File: committees.png (148 KB, 589x1051) Image search: [Google]
committees.png
148 KB, 589x1051
>>
>>54872337
Very helpful.
>>
>>54871677
Interesting, though after a few seconds googling it seems there's no 64bit build of pypy for windows.
Thread replies: 255
Thread images: 21

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

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