[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: 337
Thread images: 23

File: 1490423236884.jpg (46KB, 632x632px) Image search: [Google]
1490423236884.jpg
46KB, 632x632px
What are you working on, /g/?

Old thread: >>59586527
>>
We didn't have to choose C
Things could have been different
It didn't have to be this way
>>
Radio station software unnies
>>
File: programming-languages.jpg (129KB, 640x369px) Image search: [Google]
programming-languages.jpg
129KB, 640x369px
>>
>>59591989
Well the alternative would have been lisp machines and I bet you faggot wouldn't like that either.
>>
C was a mistake
ML was robbed
My mouth is full of dicks
>>
C#
>>
Reimplementing the unix kernel in Visual Basic 2
>>
>>59592001
explain?
>>
>>59591996
bait
>>
File: chrono.png (25KB, 672x618px) Image search: [Google]
chrono.png
25KB, 672x618px
>>59591959
doing my own std::chrono
>>
>>59592092
Gee, ya think?
>>
>>59591959
>What are you working on, /g/?
Refactoring my old hack to use a more streamlined memory allocation model.

Pic related, had to comment out a bunch of stuff to make it compile and then write stuff back in again function by function.
>>
What's a nice book to learn fortran?
Don't meme me please
>>
File: 1367854265450.jpg (2KB, 126x114px) Image search: [Google]
1367854265450.jpg
2KB, 126x114px
>>59592203
You memed yourself son
>>
>>59591959
sometimes I pass too many functions into functions, it sounds neater in my head, but have no clue what im looking at when I write it out

def convert(unit_type,unit_value): #eg convert('oz',1) >>> 29 ml >>>
ml_in_oz = 29.57353
if unit_type == 'oz':
return unit_value * ml_in_oz #returns ML

def standard_drink(percent): #returns ounces
return 60 / float(percent)


def prompt():
return input("Enter Percentage of Alcohol, or 'the anykey' for chart of popular percentages \n >")

def chart():
popular_percentages = [3,4,5,7,8,10,12,13,15,17,20,25,28,30,35,38,40,45,]
print("Percent" "\t\t" "OZ" "\t\t" "ML")
for x in range(len(popular_percentages)):
print(popular_percentages[x],"\t\t" "{}" "\t\t" "{}" .format(round(standard_drink(popular_percentages[x]),2),round(convert("oz",standard_drink(popular_percentages[x])),2)))


def main():
try:
in_oz = round(standard_drink(prompt()),2)
in_ml = round(convert("oz",in_oz),2)
print("Use {} Oz, or {} ML".format(in_oz,in_ml))
except:
chart()


if __name__ == '__main__':
main()
>>
>>59592203
use your local library or university library. They may have a physical book or they may have an ebook. either way, it's gonna be from the 70s at the latest.

Source: This is how I learned COBOL
>>
>>59592250
>sometimes I pass too many functions into functions, it sounds neater in my head, but have no clue what im looking at when I write it out
That's because you don't write in functional language.
>>
>>59592269
>Gonna be from the 70s
It'll most likely be from the 90s
>>
>>59592250
Congratulations, you've just confirmed for yourself how natural it is to think in terms of functions and function composition.
>>
>>59591989
Because it was arguably the best non-GCed compiled language available in the 70s. Pascal was shit.
>>
>>59592103
>doing my own std::chrono
>uses std::chrono
>>
Why is suddenly the enitre DTP memeing about C?
>>
>>59592318
Thankfully after the ~50 year derailment, we're beginning to acknowledge the mistake and move back to Lisp/ML family concepts.
>>
How2fix this? I want it to print 'The first of the months is January', 'The second of the months is February', so on.

http://dpaste.com/3F1GNG0
>>
>>59592334
yeah I mean just the clocks
>>
>>59592318
>C
>70s
C isn't that old.

Fortran was dominant up until well in the 1990s.
>>
>>59592341
Preferably Haskell/Idris these days desu
>>
>>59592340
Some butthurt Rust-nigger learned about buffer overflows and code injection and all the Haskellfags jumped on the train too.
>>
File: 1488821720813.jpg (457KB, 1000x667px) Image search: [Google]
1488821720813.jpg
457KB, 1000x667px
>>59592345
>>
To compilers this term. Ended up with the second highest score on my compiler for an object oriented and type inferred language. Score above me was earned by two grad students working together.
>>
>imagining all the salty C devs who have put 10+ years into that broken mistake finding that industry has moved on without them
Diamonds
>>
>>59592342
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'November', 'December']
numbers =['The First','The Second','The third','The fourth','The fifth','The sixth','The seventh','The eighth','The ninth','the tenth','the eleventh','the twelth']
for i in range (12):
for j in numbers:
for m in months:
print(j + ' of the months of the year is '+ m)
>>
>>59592342
This program is going to output 12^3 strings.
You have nested loops.
>>
>>59592395
stop wasting time on your bullshit and help make gcc7 happen already
>>
>>59592401
>nesting for loops
Yuck

Wish I could understand better why vectorized operations are a problem, but I don't understand compilers/architecture well enough
>>
>>59592348
C was created at AT&T in 1969 bruh...
>>
>>59592408
No, work on a better compiler and release it on MIT license instead of GPL communism
>>
>>59592348
Fortran wasn't structured when C was invented. It was structured around goto-like jump-to-label statements. Decent Algol clones with non trash performance were still rare.
>>
>>59592401
>the twelth of the months of the year is March
>>
>>59592456
kek i forgot october.
>>
File: 10 out of 10.png (203KB, 720x562px) Image search: [Google]
10 out of 10.png
203KB, 720x562px
>>59592456
and I spelled twelfth wrong. i would blame drugs or something but i'm completely sober.
>tfw brainlet
>>
>>59592419
The problem more is that CS students (and even moreso, people actually in industry) fail at even basic linear algebra for the most part, so using nested for loops like a chimp is all they can deal with
>>
>>59592348
Also Fortran is still dominant in scientific computing. It just happens to have adapted really well by adopting new features constantly without becoming bloated.
>>
>>59592408
Only an undergrad right now, but may apply the PhD program if I can prove I'm not a brainlet
>>
>>59592491
Jeg vet at jeg intet vet.
>>
>>59592430
>BCPL is C
They're not even syntactically related.

C as we know it today came with ANSI C in 1989. No one on /g/ even recognises C when the original parameter declaration list is used.
>>
>>59592499
>Also Fortran is still dominant in scientific computing
Not really. It's used by ageing physics professors, but any real scientific computing done on compute clusters etc use C/C++ with high-speed message passing APIs.
>>
>>59592499
I best languages evolve with relatively small communities
>>
>>59592524
BCPL was created in 1966. B was created in 1969. C Was created shortly after in 1972 (I admit I was off 3 years). C is still from the 1970s
>>
Hvis du ikke kan et fremmed språk, vil du aldri programmere godt.
>>
>>59592419
>>59592406
aighty ty a few seconds of using my brain and i figured it out

months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September','October', 'November', 'December']
numbers =['The first','The second','The third','The fourth','The fifth','The sixth','The seventh','The eighth','The ninth','the tenth','the eleventh','the twelfth']
x=0
for i in months:
z=numbers[x]
print(z + ' month is ' + i)
x+=1


Is there a better i could have accomplished this?
>>
>>59592401
This is ridiculously bugged, and prints every number month combination, including wrong ones.

Correct version ( caveat: I haven't bothered to run it).
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'November', 'December']
numbers =['The First','The Second','The third','The fourth','The fifth','The sixth','The seventh','The eighth','The ninth','the tenth','the eleventh','the twelth']

for month, num in zip(months, numbers):
print(num + ' of the months of the year is' + month)
>>
I know basically nothing about the differences between C compilers.
Do they often us LALR1 for the compatible parts of C?
>>
>>59592589
...
for i in range(len(months)):
print(numbers[i] + ' month is ' + months[i])
>>
>>59592616
ahhhhh. Ty anon.
>>59592606
Thanks m8
>>
File: dpt-poll.png (13KB, 660x249px) Image search: [Google]
dpt-poll.png
13KB, 660x249px
>>
File: dpt.jpg (164KB, 800x1000px) Image search: [Google]
dpt.jpg
164KB, 800x1000px
>>
>>59592580
Det heter fremmedspråk, din ubrukelige neger. Lær deg særskriving.
>>
>>59592694
Python is shit
>>
>>59592717
So is Google.
>>
>>59592669
Let me guess: 5 voters?
>>
>>59592643
Protip: one of the main reasons why Python is one of the best imperative languages is because of iterators. Make sure you learn to use the various iterators in the standard library. Iterators free you from indices and off-by-one errors.
>>
>>59592573
Pre-K&R C looks nothing like modern C.

Hell, even pre-ANSI C looks very little like modern C.
>>
>>59592722
Bet you have an Android phone though
>>
>even ironically writing in ML
>>
>>59592401


    months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September','october', 'November', 'December']
numbers =['The First','The Second','The third','The fourth','The fifth','The sixth','The seventh','The eighth','The ninth','the tenth','the eleventh','the twelth']


for x in range(len(months)):
print(months[x], "of the months of the year is", numbers[x])


### or


zipped = zip(months,numbers)

for x in zipped:
print(x[0], "is", x[1])
>>
>>59592728
C++ has iterators. Java has iterators.
>>
>>59592756
Wrong kind of iterator you ditz.
>>
>>59592735
It makes Google better somehow?
New versions become more and more closed.
>>
>>59592732
Please, show examples.
>>
>>59592763
What kind of iterators?
>>
>>59592780
The ones that are lazy lists in disguise, and let you do operations like zip, enumerate, comprehensions, map, collect into arraylist, and all kinds of declarative stuff.
>>
Where can I read C standard library headers?
>>
>>59592812
You mean like Haskell lists?
>>
>>59592773
// note that I don't include stdio here

main(argc, argv) // main is int, so implicit type
char** argv; // argc is int, so implicit declaration
{
printf("hello, world\n"); // implicit function declaration
} // implicit return 0


This is valid K&R style C for example
>>
>>59592812
Isn't that an iteraABLE.
>>
>>59592824
in your TE
>>
>>59592851
my python is std free too!
>>
>>59592851
>implicit
>implicit>implicit>implicit>implicit>implicit
>implicit>implicit>implicit>implicit

wew
>>
>>59592851
The only thing makes me wonder is the abscence of stdio.
>>
File: 1485927336746.jpg (51KB, 600x525px) Image search: [Google]
1485927336746.jpg
51KB, 600x525px
Is there anything besides serialize/deserialize that will let me store data in a file or database (can be sql but i hate writing sql statements) that basically equates to one or two lines like ndatabase?
>>
>>59592524
I recognize K&R style C, and I haven't even read K&R. You just have to actually look into some older C codebases, I think even the current Nethack code uses K&R style parameters.
>>
>>59592732
Can you give an example of pre-K&R C and how it differs from pre-ANSI C?
>>
>>59591959

Putting all my shit into Docker containers.
>>
>>59592851
So what does PRE-K&R C look like?
>>
>>59592949
>cucking all your shit
Why?
>>
>>59592419
Two array should work just fine, access them in one loop with same index.
Here is C example:
#include<stdio.h>
void main(void){
char months[12][10]={"January",///}
char numbers [12][16]={"..",//
for (int i=0;i<12;++i){
printf("%s month is: %s",numbers[i],monts[i]);
}
}
>>
#define NK_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2

What does this make?
>>
>>59592943
>Can you give an example of pre-K&R C
It's hard to come by any actual examples, because before K&R-style C, it was mostly an internal programming language used at AT&T/Bell Labs.

>how it differs from pre-ANSI C?
Implicit types and implicit function declarations, for example, are considered invalid C.

>>59592943
>>59592919
Other examples involve parameter passing. With K&R style argument declaration, you also need to pass parameters reverse.

foo(a, b)
{
return a;
}

bar()
{
printf("%d\n", foo(3, 5)); // this actually prints 5
}
>>
>>59592851
Warnings in gcc, clang, cc.
>>
>>59593015
it joins 2 arguments
>>
>>59593015
check it for yourself
>>
>>59593033
Yes, because this isn't valid C89/90.

But it is valid K&R C. First edition K&R is filled with these.
>>
>>59592972

Thinking containers are here to stay. Don't know about Docker specifically, but seems to have mind share.

People who don't deploy might not understand.
>>
File: file.png (13KB, 650x221px) Image search: [Google]
file.png
13KB, 650x221px
How do I get tesseract to not suck ass?
>>
>>59593026
>>59592851
Also one line comments (aka // comments) aren't technically legal, it should be /* comment */
>>
>>59593015
That just concatenates two things at compile time. Not sure why they used such a verbose name for it.

>>59593026
So how do you tell K&R and pre-K&R C apart? Both use the weird so-called "K&R" way of declaring function parameters, right?
>>
>>59593050
>first edition K&R
Invalid syntax, it was very long time ago, examples from second edition works just fine.
>>
>>59592832
Sort of. They aren't quite as powerful as Haskell's lists, but you can map/filter/zip/fold them, or do more advanced itertools operations on them.

They are the reason why python's for loops and generator expressions are so nice. If all your python for loops look like for i in range(...) you are missing out.
>>
File: 1489115871059.jpg (20KB, 480x451px) Image search: [Google]
1489115871059.jpg
20KB, 480x451px
>groovy
what the fuck
its so digusting
>>
File: beavis computer.gif (337KB, 492x376px) Image search: [Google]
beavis computer.gif
337KB, 492x376px
I'm trying to learn how to do buffered I/O in Java.

I'm not certain if I'm doing this right. Does a BufferedInputStream need to use the read() method or the read(byte[]) method to correctly read buffered data?

It seems to work fine just using read() and doesn't work when using read(byte[]), so I'm a bit confused, since I thought you needed to read from the stream indicating a byte array for the buffer. But I guess that isn't necessary since I established the buffer size in the constructor?

Any insight is greatly appreciated!


import java.io.*;

public class tester {

public static void main() throws Exception {

int bufferSize = 8 * 1024;

InputStream input = new BufferedInputStream(new FileInputStream("input.png"),bufferSize);
OutputStream output = new BufferedOutputStream(new FileOutputStream("output.png"), bufferSize);

int data = input.read();

while(data != -1){
output.write(data);
data = input.read();
}

System.out.println("Done!");

input.close();
output.close();

}

}
>>
>>59593079
>So how do you tell K&R and pre-K&R C apart?
There is no pre-K&R C out there, because first real release of C was in 1975 which is K&R C. Before that it was just a work in progress.

>>59593095
Follow the discussion, we are discussing when C became C. If you dismiss first edition K&R as invalid syntax, then my original point, namely that modern C came in the 80s, stands.
>>
Why the fuck do so many of you sheeple code in C? Does it stand for Circlejerk?
>>
>>59593114
>[Return] [Catalog] [Top] 101 / 12 / 30 / 1 [Upda
test your code, how fast is it compared to non buffered?
>>
>hurr durr durr I'm a human calculator
literally what it sounds like in here

lol anyhoo, hoping one of you greasy nerds can help me with my CS hw, girl btw (=
>>
>>59593135
C stands for reliable software that respects your freedom and time.
>>
>>59593138
usually its a combination of these
>muh efficiency
>muh portability
>muh special snowflake
>>
File: 1444180068224.png (10KB, 327x173px) Image search: [Google]
1444180068224.png
10KB, 327x173px
>school library has 90 books on Ada
>>
>>59593144
First for being a TI 84 +
>>
>>59593144
>girl btw
Do you know rules?
>>
File: so_good.png (66KB, 659x609px) Image search: [Google]
so_good.png
66KB, 659x609px
>tfw finally fixed persistent Heisenbug in my C codebase
>>
>>59592269
Fortran isn't that legacy. It's still actively developed and used.
>>
>>59593154
Good library btw, I hope even more for C language?
There is still people who use Ada/Fortran, sometimes it's more efficient than C.
>>
>>59593151
meant for
>>59593135
>>
File: rust.png (165KB, 2000x2562px) Image search: [Google]
rust.png
165KB, 2000x2562px
>yfw Rust leaks memory
>yfw this won't be fixed because "memory leaks are still memory safe"
>>
>>59593127
>There is no pre-K&R C out there,
What about the source code linked on this page, which it claims to be from 1972/73?

https://www.bell-labs.com/usr/dmr/www/primevalC.html
>>
>>59593154
Scan all books and share on piratebay.
>>
Java aint so bad lads
>>
>>59593144
If you actually posted what you need help with, people might be more inclined to help you.
>>
I made a addition calculator
def find_number(num):
ret = 0
for x in range(num):
ret+= True
return ret


def addition(int_1,int_2):
num1 = find_number(int_1)
num2 = find_number(num1+int_2)
return num2


print(addition(4,4))
>>
>>59593207
>fell into rust meme.
pajeet.
>>
File: c_rust_java.png (182KB, 693x423px) Image search: [Google]
c_rust_java.png
182KB, 693x423px
Is this accurate?
>>
>>59593138
It's definitely faster.

I guess I was just thinking that I needed to edit my read() and write() methods to include the buffer size in them, e.g.: read(byte[]) and write(byte[], int, int). But I suppose not.
>>
>>59593200
Couple hundred C++ books
>>
File: 1489839734144.jpg (50KB, 461x407px) Image search: [Google]
1489839734144.jpg
50KB, 461x407px
>>59593210
>windows user
>newlines are fucked up in notepad
>>
>>59593248
Whith C++ in the middle 100%.
>>
>>59593207
>>yfw Rust leaks memory
Thats pretty funny, hows it happen?
Unsafe or safe?
Is it atleast a public bug?
>>
>>59593207
>yfw Rust leaks memory
Source!
>>
>>59593266
>>59593216
Those books can help C++ programmers, which usually don't know how really use it.
>>
>>59593281
heap allocations
>>
>>59593269
>1972
>no windows
>UNIX epoch
It was good time I guess.
>>
Trying to fix a memory leak in my DirectX game :(

Anyone feel like trying their hand?

>>>/wsr/285872
>>
>>59593272
For example, panicking in a destructor during a panic can cause such destructor to be leaked. It's known by the team but isn't a major concern for now since memory leaks are considered memory safe.
>>
>>59593281
https://github.com/redox-os/redox/issues/855
>>
Why does a plain \n not work in Windows
\cr or whatever it is makes sense why it's there I guess, but \n should still add a newline
>>
>>59593210
>What about the source code linked on this page, which it claims to be from 1972/73?
Yes, this is pre-K&R C.

Note that every function must specify what other functions they call in a specifier list.
>>
>>59593373
>2017
>Using botnet+backdoor OS.
>>
module find_palindromes;

import std.stdio;
import deduplicate_string_array;
import sort_by_descending_length;

string[] find_palindromes(in string str)
{
string[] found_palindromes = [];
for (int i = 0; i < str.length; i++)
{
if ((i + 1 < str.length) && str[i] == str[i + 1])
{
string current_palindrome = "" ~ str[i + 1];
int k = 1;
while ((i - k >= 0) && (i + 1 + k < str.length) && str[i - k] == str[i + 1 + k])
{
current_palindrome ~= "" ~ str[i + 1 + k];
k++;
}
found_palindromes ~= current_palindrome;
}
}
deduplicate_string_array(found_palindromes);
sort_by_descending_length(found_palindromes);
return found_palindromes;
}

module deduplicate_string_array;

//re creating the array without duplicate values
//updates the array, returns void
void deduplicate_string_array(ref string[] elements)
{
for (int i = 0; i < elements.length; i++)
{
for (int j = i + 1; j <= elements.length - 1; j++)
{
if (elements[i] == elements[j])
{
elements = elements[0 .. j] ~ elements[j + 1 .. $];
}
}
}
}

module sort_by_descending_length;

//updates the array, returns void
void sort_by_descending_length(ref string[] elements)
{
for (int i = 0; i + 1 < elements.length; i++)
{
if (elements[i].length < elements[i + 1].length)
{
string temp = elements[i];
elements[i] = elements[i + 1];
elements[i + 1] = temp;
}
}
}
>>
>>59593363
>It's known by the team but isn't a major concern for now since memory leaks are considered memory safe.
lmao, wtf?! The absolute STATE of rust.

What a useless meme language.
>>
>Ask question about OS convention
>Assumed to be using that OS
The absolute state of namefags
>>
>>59593418
>that_naming_convention
Terrible!
>>
>>59592773
>>59592943
The oldest C code I know of are the snippets in this book (1976)

http://www.lemis.com/grog/Documentation/Lions/index.php
>>
>>59591959
Can I get some help guys? I'm retarded when it comes to programming and I am trying to make a C++ program that takes an integer as a command line argument and checks if it is odd or even.
For the checking odd or even part I was going to take the input, divide it by 2 and get the answer both in int and float form, and then compare them in an if statement to see if they're odd or even. My biggest issue with writing this is that I have no idea how arguments work.

Would it look something like this?
#include <iostream>
int main(int argc, char* argv[]){
if (argc !=2)
cerr<<Invalid input<<endl;
int x;
float y;
y=argc[1]/2;
x= argc[1]/2;

if (x==y)
cout<<Your number is even;
else
cout<< Your number is odd;

return 0
}
>>
File: 1481916546254.jpg (47KB, 645x968px) Image search: [Google]
1481916546254.jpg
47KB, 645x968px
>>59593458
I was anticipating why I didn't use Generics, or why am I not using concurrency but /g/ never failed to surprise me. LOL
>>
>>59593458
Good for defining types because declarations are infrequent and the convention is clear
>>
>>59593418
Why are you reposting this trash?
I told you to fix it.
>>
Why Haskell programmers can't stop talking about Haskell?

They are immutable!
>>
>>59593503
Which one? It's a different program though
>>
>>59593363
Panicking in a destructor just calls abort. The memory isn't really leaked because the OS cleans it up immediately.
>>
>>59593504
r u avin a giggle m9
>>
>>59593491
Might be easier to compare (x/2)*2 with x. It will be smaller than x if it's odd.
>>
>>59591959
So I installed visual studio 2012 and suddenly I don't need semicolons at the end of statements.

What gives?

I want to get familiar with the proper language not some simplified shit.
>>
>>59593435
This only happens if you write your own destructors and have them throw exceptions. You have the same issue in C++. Failing to release memory is a very unusual event.

Memory leaks are still memory safe though, that is the entire point of GCed languages. Leaks don't cause UB like dereferencing pointers to freed memory does.
>>
>>59593525
It's just one case among other possibilities. For instance you can also forget in safe blocks. Again memory efficiency is not the goal of Rust, so this is acceptable.
>>
>>59593491
you might try
return x%2 == 0
>>
>>59593491
import std.stdio;
import std.conv;
void main(string[] args)
{
writeln((to!(int)(args[1]))%2==1?"Odd":"Even");
}
>>
>>59593574
Allowing the user to suppress a destructor manually is not a case of "Rust leaks memory".
>>
>>59593491
just use modulus op (%) to check if there's a remainder or not. If there is, it's odd, if there isn't it's even.
>>
>>59593595
Oh well, no point arguing I guess.
>>
>>59593544
What language are you using?

>>59593549
Dereferencing invalid pointers isn't bad because of ``undefined behavior", rather it's UB because it's bad.
>>
>>59593618
Why did you remove your name? Easier to filter out idiots that way
>>
>>59593623
C#, maybe i should've posted in the stupid questions thread or something.
>>
>>59593491
#include <iostream>
#include <cstdlib>
using namespace std;

int main(int argc, char ** argv) {
if(argc != 2)
cout << "Invalid Num Ops" << endl;
else {
int a;
if(a = strtol(argv[1])) //Might want to check for range error
cout << a % 2 == 0 ? "Even" : "Odd" << endl;
else
cout << "Invalid Arg" << endl;
}
return 0;
}
>>
Am I undefined behavior?
>>
>Rust leaks memory.
Fake news!
>It is safe to leak memory in Rust.
Terrific!
>>
>>59593693
>I am
>you be
>UB
>undefined behavior
>>
>>59593693
You're a slut.
>>
>>59593699
http://huonw.github.io/blog/2016/04/memory-leaks-are-memory-safe/
It's true.
>>
>>59593699
>this new
>>
>>59593713
Yes, it is. >>59593207 was being very crooked about it.
>>
File: fantastic.png (78KB, 869x957px) Image search: [Google]
fantastic.png
78KB, 869x957px
A while ago I implemented a markov chain fantasy name generator. It took in a source file of 1000 real names, and spit out a bunch of vaguely fantasy-sounding names. Unfortunately, a lot of the results are garbage, especially when you get to the really long names:

Alerraxwenshonniquelsonshoe
Amariamonnionackylakaimitch
Remphriquiellexishonaleston
Maresuelsondrishaullillerton
Lukerlandrickobelazequellannord

I'm therefore working on a little website that will let people vote on their favorite names out of a random sample from the set of 6466 names. After I get a lot of data, I'll compile a list of the top 100 or 1000 or so.

Development has been going well so far (pic related). The next thing I want to do is change it from "which of these names sound good?" to an upvote/downvote for each name in the sample. That will let me distinguish between bad names and names which no one has seen yet.
>>
==29976== HEAP SUMMARY:
==29976== in use at exit: 17,372 bytes in 24 blocks
==29976== total heap usage: 24 allocs, 0 frees, 17,372 bytes allocated
==29976==
==29976== LEAK SUMMARY:
==29976== definitely lost: 0 bytes in 0 blocks
==29976== indirectly lost: 0 bytes in 0 blocks
==29976== possibly lost: 0 bytes in 0 blocks
==29976== still reachable: 17,372 bytes in 24 blocks
==29976== suppressed: 0 bytes in 0 blocks



wat do?
>>
Who is this thread quoting?
>>
>>59593751
Stop using Rust.
>>
File: 1490562562881.gif (133KB, 497x501px) Image search: [Google]
1490562562881.gif
133KB, 497x501px
>>59593583
>>
I just want decent statically typed and compiled language that doesn't require huge vm like java.
>lisp
Too verbose, static typing isn't standardized.
>sml
no good implementation, no macros.
>c
fine but developing sucks, dynamic loading requires lot of boilerplate and you need to keep track of the frees.
>chapel
looks promising but no libraries or community, very easy C interface though that kind of helps with the library part, also operation overloading so it's probably shit.
>ada,fortran
>end
>go
Rob Pike is openly faggot and likes the smell of his own farts way too much.
> sepples
convoluted cluster fucks that no sane person would want to touch.
>>
>>59593758
Thanks for the tip, CIA
>>
Question about golang.

I want to use a postgres database for storage. How to proceed? I'll want data transfer objects and whatnot.

Are there any good, working solutions which let me define the database schema with SQL, and then generate dto's from that? Without first writing the SQL to a database?
>>
>>59593766
Start using Rust.
>>
>>59593762
#include <stdint.h>

/**
* @param n n
* @return d on success, -1 on failure
*/
int64_t f(uint8_t n)
{
if (n <= 1) return n;
/* if n is greater than 92, fail */
if (n > 92) return -1;
n -= 2;

uint64_t a = 1, b = 1, c = 0, d = 1, e = 1, f = 0;

while (n) {
uint64_t g, h;
if (n & 1) {
g = a * d + b * e;
h = b * d + c * e;
f = b * e + c * f;
d = g;
e = h;
}
g = a * b + b * c;
a = a * a + b * b;
c = b * b + c * c;
b = g;
n >>= 1;
}

/* return d */
return d;
}
>>
>>59593766
>convoluted cluster fucks that no sane person would wan
Try D
>>
>>59593758
It's C, faggot
>>
>>59593773
Yes, copy and paste code until the errors go away.
>>
>>59593779
>/* return d */
> return d;
ok
>>
>>59593781
I thought C programmers never made mistakes?
>>
>>59593766
Idris?
>>
>>59593758
Where does it say Rust?
>>
>>59593804
>>59593777
Nobody wants to program with meme language.
>>
What data structure should i use if i need to have every elements accessed, performed some operation on it, and then return it to the end of the "array" while 2nd one comes to first place?
>>
>>59593779
stop posting this shit faggot


no one cares
>>
>>59593815
The memory leakage says it all.
>>
File: anal beads.png (994B, 128x44px) Image search: [Google]
anal beads.png
994B, 128x44px
>>59593779
Kill your professor
>>
>>59593819
>>59593828
Is it school holiday?
>>
>>59593825
A queue.
>>
>>59593834
Memory leaks are core a feature of C
>>
>>59593803
i didn't use a single free in the code tho
>>
>>59593828
>doesn't appreciate optimized code
>>
>>59593751
>24 allocs, 0 frees
>wat do
Did you consider freeing the memory you allocated?
>>
>>59593838
How do i send elements to the end and will other elements automatically be shifted?
>>
>>59593734
Why use a markov chain though? Randomly choose a first name, then recurse on decreasing prob. to randomly choose another name to concatenate or increasing probability to stop. I can't imagine the distribution over the current names given the some previous name is unique in any way for any name.
>>
>>59593837
yeah, that's why you're here
>>
>>59593835
Why do you name all your images anal beads?
>>
>>59593848
Grammar leaks are a core feature of your post.
>>
>>59593871
my keyboard is broken
>>
>>59593867
priority queue
>>
>>59593866
yeah i know i have to free the memo.

my question is, my program is a linked list that represents a tree.

where in the program should i use free?

i have a function that prints the tree. should i free the node after i print it?
>>
>>59593867
You send them to the end with push (or a similarly-named method).

You get them from the top with pop (or a similarly-named method). If you invoke pop again, you'll get the next element.
>>
Fact: OCaml programmers are the most powerful race in the world.
>>
>>59593870
So how are your homeworks coming along? Are you watching too much cartoons?
>>
Some time ago I felt like I wasn't not precise enough many times.
So, I've started to chew gum. I must say, I feel to be more precise now!
Wanna know what chewing gum helped me?

Doublemint.
>>
>>59593907
Idris > Haskell > Scala > OCaml
>>
>>59593860
>doesn't explain what the hell is that code

>>59593908
kys
>>
>>59593692
>>59593491
Why are your programs so unnecessarily long?
>>
roast me /g/
#!/bin/bash

F="Fizz"
B="Buzz"

fb () {
t=${F[$(($i % 3))]}
f=${B[$(($i % 5))]}
if [ -n "$t" -o -n "$f" ]; then
echo -n $t$f
else
return 1
fi
}

for i in `seq 1 100`; do
fb || echo -n $i
echo
done
>>
>>59593909
where do I buy longdoublemint?
>>
>>59593924
>kys
Is that the new insult among the cartoon watchers?
>>
>>59593900
Efficiently freeing memory is actually a very hard task. If your code is not real-time then you can afford any pose caused by the call to free. In this situation I advise calling it just after you are done using the data, so that would be right after you call your tree printer, assuming that's the last place you're using it.
>>
>>59593900
If it's not needed any more, you free it.
>>
>>59593924
Run it and see.
>>
>>59593900
No, you should have another function which frees all the resources your tree uses and call it when you no longer need the tree.

Don't shove that shit in a print function.
>>
>>59593909
How it feels to chew 5 gum?
>>
for i in range(1, 106):print("FizzBuzzBazzFizzBazz"[(i**4%5)*8+((1-i**2%3)^(1-i**4%5))*4:8+(1-i**6%7)*4+((1-i**2%3)&(i**4%5))*8] or i)

thanks to Euler I can waste less of my time on fizzbuzz offshoots.
> tfw you wasted 15 minutes on this
>>
>>59593905
I'm looking into it, thanks, in c# it's enqueue() and dequeue()
>>
>>59593936
>>59593943
my code is
struct node *root;
....
....
print_tree(root);


if i free the tree after i print it, the pointer is at the last element, and its going to be a shitfest
>>
>>59593956
for i in range(1,101):print"FizzBuzz"[i*i%3*4:8--i**4%5] or i
>>
>>59594003
> only fizzbuzz and not fizzbuzzbazz
>>
>>59594013
>implying i care
>>
>>59594019
> implying implying
>>
>>59593869
I'm having a little trouble understanding your comment, and it makes me think that maybe you don't understand how my name generator works? It's a markov chain over all the characters in the set of the original 1000 source names.

I usually get decent results, when I'm not at the extremes of name length:

Kyris
Gilo
Curne
Stett
Javin
Marus
>>
>>59593986
That can't be right, even after print_tree is called root will still point to the top.

If it was print_tree(&root) it could be possible but that would be terrible design.
>>
>>59593931
It's deprecated.

>>59593928
Unreadable.
>>
Do any of you do that tiny filesize demoscene shit? If so I am really impressed with that sort of thing.
>>
>>59594036
this is my tree definition and print_tree function. the l1, l2 and l3 are the tree leafs.
struct node {
struct node *l1,*l2,*l3;
struct node *next;
char *type;
};

void print_tree(struct node *tree, int depth)
{
if (tree->type != NULL)
puts(tree->type);

if (tree->l1) print_tree(tree->l1, depth + 1);
if (tree->l2) print_tree(tree->l2, depth + 1);
if (tree->l3) print_tree(tree->l3, depth + 1);

if (tree->next)
print_tree(tree->next, depth);
}


how would i write a function to free the memory?
>>
>>59593928
import std.stdio;

void main()
{
foreach(i; 1..100)
{
writefln(i%15==0?"Fizzbuzz":(i%3==0?"Fizz":(i%5==0?"Buzz":"%s")), i);
}
}
>>
One guy couldn't name his new language. He couldn't decide for long, and he felt so despaired about it, so he decided to name the language by the first phrase he would hear.
He went out for a cigar break, and the other guy noticed what kind of cigarettes our hero smoked.

"O, Camel!"
>>
>>59594030
Ah yes, that makes much more sense, generating the prob. distributions of next characters based on the current character from your set of all names.
>>
Can anyone give me a birdmin challenge?
>>
>>59594135
The same way you print them senpai, just make sure you free the current node last.
>>
>>59594135
Try recursing like you're doing and call free(tree) at the end of the function. Maybe free tree->type if it's dynamically allocated.
>>
Should I write my function definitions before or after main
>>
>>59594277
Doesnt matter. Functions should not be in the main file anyways
>>
>>59594277
Before main, otherwise you won't be able to call them.
>>
>>59592971
Not really relevant; the first edition of K&R's book was early enough that nobody cares about what the really old stuff looks like.
>>
>>59594277
After. Main is the entry point of your program, so it makes sense for it to be the first definition.
>>
>tfw my C programming lecturer forces us to write code in such a way that it can't be self-explanatory and thus requires more comments
>>
>>59594295
No, the compiler does the job for you, unless your compiler is shitty or you are running a scripting language
>>
>>59594295
Actually you can declare functions before main and write the functions after main.
>>
>>59594307
>C programming lecturer
Is that a thing now?
>>
>>59594307
>learning C in college
Why?
>>
>>59593766
>compiled language
Too bad. There isn't such a thing.
>>
>>59594324
>>59594325
It's a prerequisite for a lot of other courses and includes general UNIX and software development material as well.
>>
>>59594277
The way I use is it depends how important reading the function is to understanding the file.

If it has a descriptive name and somebody reading the file wouldn't care how it's implemented, forward declare and shove it at the bottom.
>>
>>59594308
>t. has never programmed in C
>>
>>59594330
Explain yourself.
>>
>>59594343
>t. retarded
He said definitions, not declarations.
>>
>>59594307
>>59594325
>>59594343
Who the fuck are you quoting, retards?
>>
>>59594332
It used to be assumed that you'd be proficient in C before starting college, or that you'd learn it in your own time while there.
>>
>>59594343
Fucking C toddles should be ousted
>>
>>59592146
You do realise multiline commenting exists?
>>
>>59594343
Fuck off idiot
>>
>>59594367
Yeah, I wish. I'm already a decent C programmer, being stuck in this course for a semester and listening to retards struggle to understand pointers is painful. The course work is fairly challenging if you want bonus points, at least.
>>
>>59594351
It's self-explanatory. I don't think any language would be retarded enough to state that only a compiler would be a valid implementation of that language.
>>
>>59594360
Fuck off back to you know where
>>
>>59592537
Can't speak for scientific, but my actuary buddy's firm heavily uses it
>>
>java homework
>have to create queue and stack classes
>need to navigate mazes through different search algorithms utilizing the classes we built
>feel like a brainlet because i can't wrap my head around how to retrieve the shortest routes

thanks for reading my blog
>>
>>59594357
Even declarations are only required in C99.
>>
>>59592537
>high-speed message passing APIs
There's a reason these exist in Fortran too
>>
>>59594406
who said this?
>>
>>59594423
>I'm going to keep posting my retardation
>>
>>59594421
You're missing the point.
Fortran is deprecated.
C/C++ is the future.
>>
>>59594423
>>>/global/rules/6, now fuck off.
>>
>>59594445
nobody wrote this.
>>
>>59594237
>>59594198
using
void free_tree(struct node *tree)
{
if (tree->c1) free_ast(tree->c1);
if (tree->c2) free_ast(tree->c2);
if (tree->c3) free_ast(tree->c3);
if (tree->next) {
free_ast(tree->next);
}

free(tree);
}

valgrind says
==30448== HEAP SUMMARY:
==30448== in use at exit: 16,476 bytes in 8 blocks
==30448== total heap usage: 24 allocs, 16 frees, 17,372 bytes allocated
==30448==
==30448== LEAK SUMMARY:
==30448== definitely lost: 13 bytes in 4 blocks
==30448== indirectly lost: 0 bytes in 0 blocks
==30448== possibly lost: 0 bytes in 0 blocks
==30448== still reachable: 16,463 bytes in 4 blocks
==30448== suppressed: 0 bytes in 0 blocks
>>
>>59594457
>I'm going to keep posting my retardation
>>
>>59594452
did you mean to reply to these guys?
>>59594406
>>59594445
>>
Strictly LALR1 languages are the future
>>
>>59594423
I did faggot
>>
>>59594467
Shouldn't you free your char* too?
>>
>>59594451
>C/C++ is the future.
kek. Is there a better way to announce your NEET status?
>>
>>59594469
link to the post you're quoting?
>>59594477
>java homework
>have to create queue and stack classes
>need to navigate mazes through different search algorithms utilizing the classes we built
>feel like a brainlet because i can't wrap my head around how to retrieve the shortest routes
nobody said this before you, though.
>>
>>59594399
If most implementations of the language are compilers, it would be stupid to call such language interpreted one.
>>
>>59594474
>not Backtracking LALR
>>
what is UML?
>You will create UMLs for all classes
side note: this is a java intro class
>>
>>59594467
Also why are you using 2 different functions (free_tree and free_ast) when they have the same type?
>>
>>59594494
Did your parents drop you on your head when you were a small child?
>>
>>59594490
>bashing sepples
kek. Is there a better way to announce your NEET status?
>>
>>59594506
>it would be stupid to call such language interpreted one
Indeed, since no language is either an interpreted or compiled language.
>>
>>59594467
Is tree->type dynamically allocated? free(tree->type).

If that's not it, compile with -g and use --leak-check=full.
>>
>>59594509
Do reasonable bottom up parsers actually exist?
>>
>>59594514
Universal Modeling Language

/g/ pretends it's not important but it's an essential tool in industry where you need to document everything
>>
>>59594543
Menhir
>>
>>59594509
>>59594514
>>59594526
I don't think anyone said that.
>>
>>59594481
if i do free(tree->type) at the end, it just yields a bunch of Invalid read of size 8 and invalid addresses
>>
>>59594547
I have worked in industry for 6 years and I have never once used UML.
>>
>>59594526
C++ is okay, but spewing bullcrap about how C is "the future" is a dead giveaway of NEETdom
>>
Can somebody that knows Sql help me please? I'm really dumb at this, I don't know why it won't let me add in this foreign key.

It says "key column 'department_id' doesn't exist in table," but I did a select statement on the department table and it showed up then.
thank you, sorry for the question
>>
>>59594543
https://en.wikipedia.org/wiki/Comparison_of_parser_generators
>>
>>59594555
You did it before freeing tree right? Post code.
>>
>>59594563
>bullcrap
Underage posters pls leave
>>
>>59594563
>C++ is okay,
>>>/r/ibbit
>>
>>59594577
A-are you trying to make it reference its own key as a foreign key?
>>
>>59594551
Okay right
I've looked at ocaml but only briefly. Seems really cool
>>
>>59594602
Sorry gate keeper, you have to try harder
>>59594589
What cartoons are you watching?
>>
>>59594588
void free_tree(struct node *tree)
{
if (tree->c1) free_tree(tree->c1);
if (tree->c2) free_tree(tree->c2);
if (tree->c3) free_tree(tree->c3);
if (tree->next) {
free_tree(tree->next);
}

free(tree);
free(tree->type);
}
>>
>>59594618
I haven't watched cartoons in years.
>>
>>59594624
Of course this won't work since tree is no longer allocated, hence you cannot acces tree->type. Put it the line before free(tree).
>>
>>59594632
All C babbies watch cartoons, don't try to hide it
>>
>>59594624
No, switch those frees around.
>>
>>59594562
how big are your projects
>>
>>59594618
>gate keeper
Oh fuck not you again, what's next, you gonna moan about "elitism" again?

>>59594637
I'm not even a C programmer
>>
>>59594611
Well I'm the OCaml shill and I really love it, but it's quite specific to the language. Also the license might be bothersome depending on your use case. Otherwise I think it's GOAT.
>>
New thread:

>>59594649
>>59594649
>>59594649
>>
>>59594648
OCaml is fucking trash though. It's literally untyped garbage.
>>
>>59594634
>>59594639
but the memory is not dynamically allocated. even if i switch it outputs a bunch of errors.

oh well
>>
>>59594645
Pretty big
>>
>>59594669
--leak-check=full
>>
>>59594667 (You)
>>
>>59594671
we use it all the time desu
>>
>>59594671
for you
>>
>>59594686
Has dynamic typing completely killed off your brain? You're duplicating the ***
>>
>>59594604
I'm trying to add the attribute department_id from the department table to employee table.....
>>
>>59594690
I'm sorry anon, that must be mind-numbingly shit
>>
how do I change the compiler to look for mang instead of main
>>
Can you add 2 different types of objects into Queue?
>>
>>59594932
>objects
Fuck off back to your subreddit
>>
>>59594803
int main() { return mang(); }
>>
>>59594947
?

i literally meant objects
>>
>>59594954
no
>>
>>59595008
Yes, fuck off to your subreddit.
>>
>>59593542
>>59593578
>>59593583
>>59593601
>>59593692
Thanks, I totally forgot about the modulus operator.

>>59593927
That second guy wasn't me, but C++ is new to me, so that's why there's stuff that is probably not necessary in my code.
>>
>>59593665
>C#
Retard. Normal people use C.
>>
>>59594803
#define mang main
>>
Tell me about interesting DSLs you've made or come across
>>
>>59595398
I've made an anime DSL which tells me which anime to watch.
>>
Can someone explain to me why this code doesn't display in my python interpreter?
[$code]
def func(Choice):
input("Do you " + colored("run ", 'blue')+"or " + colored("attack? ", 'blue') + "")
[$/code]
>>
>>59596647
Shit I fucked that up. The question still stands.
Thread posts: 337
Thread images: 23


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