[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: 343
Thread images: 19

Previous thread: >>59064420

What are you working on, /g/?
>>
>Created before the bump limit
>/pol/shit
Delete this thread, you fucking idiot.
>>
just got done figuring out android NativeActivity using the raw native_activity (not native_app_glue) which wasn't the easiest considering the lack of documentation and examples. the "boilerplate" i wrote is 400 LOC but it's all super clean and readable.
>>
>>59070162
and this is with the equivalent of GLSurfaceView and all the activity callbacks and MotionEvent equivalent
>>
QUICK! Give me the number of permutations of the sequence of numbers 1 through n that when used to build a binary tree result in a fully balanced tree. For n = 5.
>>
>>59068759
>>59069091
>>59069129
>>59069908
I think this is right: http://pastebin.com/HFmuN22b

It tries to support values starting partway through a byte using bitwise shifts.
>>
File: random.webm (2MB, 700x560px) Image search: [Google]
random.webm
2MB, 700x560px
>>
thank you for using a Trump image
>>
delete this thread
>>
>>59070396
3 1 4 2 5?
I'm not sure I understood the question perfectly.
>>
>>59070464
DELETE MY ANUS
>>
(roll 2d4+3+4d6)
(roll "2d4+3+4d6)
(roll 2d4 34d6)
#D2d4+3+4d6
So, what does /g/ thinks look better?
>>
>>59070417
Improved: http://pastebin.com/r7tKdH4e
>>
>>59070482
Oh no. I skipped the 'number of permutations' part. Obviously not correct.

Is this meant as a programming challenge?
>>
>>59070396
Only if you do my homework first.
>>
>>59070063
Could someone post that image of a keyboard with emacs shortcuts on top?
>>
Why is casting malloc bad?
>>
>>59070063
anon in one of the previous threads suggested I try header omission in Ethernet packets.

Anyone know of any implementations I can look at? So far all I found are IEEE papers on the subject and I am not feeling like spending a few days trying to replicate their findings.
>>
>>59070686
Because you only have to do that in c++and at that point you should just use new
>>
I'm trying to figure out how to break the encryption on some .arc files so I can help a translation group with their efforts towards cracking a Japanese game and making an english patch for it.

Could any of you point me in the right direction for how to do that?
>>
>>59070686
In C code its bad because it's another place to change your code when you change what type you're allocating. There's implicit casting going on. You shouldn't do it because it's unnecessary.
In C++ it's bad because you shouldn't use malloc. New is typesafe.

I'm assuming you're new so I wouldn't go into it more as it might cause confusion.
>>
File: 1486348056927.png (853KB, 861x889px) Image search: [Google]
1486348056927.png
853KB, 861x889px
>want to get into machine learning meme
Is Tensorflow good?
>>
wow what an awful shitty thread created by an autist before the bump limit
>>
>>59070840
Since its a game resource file the game has to use the key at some point. If you hook the games resource loading functions and pause the process when it accesses the file you should be able to read the decryption key out of memory.

Beating encryption is hard any other way.
>>
>>59070925
Got it. I'll do that sometime in the next few hours then. Thanks anon
>>
>>59071032
It's of course possible that it's loaded into memory and decrypted at a later time. But I deem that unlikely. It's worth mentioning so you don't tear your hair out when there doesn't seem to be a decryption step.
>>
File: Screenshot_2017-02-23_00-43-40.png (690KB, 1145x850px) Image search: [Google]
Screenshot_2017-02-23_00-43-40.png
690KB, 1145x850px
i'm adding a large new functionality that will let users search for albums

this is a preview of the action
>>
>>59071077
Go away, no actual progress allowed here.
>>
How would I go about using the random package in Java, to skip a specific set of coordinates but randomise everything else?

For example, if I have a 2-dimensional array [10][10] & want to randomise every coordinate but [0][0].

Any help is much appreciated.
>>
>>59071376
in that particular case, do random(9) instead of random(10) and simply add 1 to the outcome
>>
>>59070866
I've been studying data structures and since my proffessor is shit I've been learning on youtube videos and through google. I've seen that many, many people cast the return value of malloc and just yesterday I read somewhere in /g/ that it was a bad thing to do.
>>
Summarise to me what a database is and languages like SQL are
>>
>>59071423
It's not really that bad, it's just dumb.

>C: redundantly casting something that's implicitly cast
>C++: using malloc instead of new
>>
>>59071470
So for example;
node_t *node = (node_t*) malloc(sizeof(node_t));

should be:
node_t *node = malloc(sizeof(node_t));

Or is there a difference in the way to use malloc that I should start using?
>>
Is it wrong for me to like Java? Why would I use C++ for anything high level?
>>
>>59071451
struct scheme{
int id;
char name[128] ;
char somethingelse[128];
int date;
}

scheme * database;


something like this with some sophisticated lookup algorithms?
>>
File: 1485187299820.png (64KB, 500x500px) Image search: [Google]
1485187299820.png
64KB, 500x500px
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=5edabca9d4cff7f1f2b68f0bac55ef99d9798ba4
>>
>>59071423
Thx anon
>>
>>59071617
Meant for:
>>59071410
>>
File: 1485818071049.jpg (126KB, 590x417px) Image search: [Google]
1485818071049.jpg
126KB, 590x417px
Dont you just wish you knew everything about a programming language and you didn't have to learn it?

I don't understand why humans have to be subjected to the shit that is library learning FUCK
>>
>>59071524
If you include a cast, its portable. But in ANSI C, the cast is useless.
>>
>>59071672
Real programmers don't use libraries.
>>
>>59071533
java and C++ are unironically the best languages
>>
>>59071733
Except I have no idea how I can go from standard library C++ to a fully functional GUI.
>>
>>59071774
Python C++ Javscript masterrace.
>>
File: sample.png (10KB, 599x138px) Image search: [Google]
sample.png
10KB, 599x138px
Hey guys. Anyone good with SQL statements? Having a bit of trouble.

Without giving huge specifics on each table, I am supposed to display each Employee who has a salary greater than all lowest paid employees per department. So I thought cool, ill do a subquery getting the minimum salary of each department, then in the outer query set salary greater to that. I don't quite understand why it doesn't work. Shouldnt the subquery give multiple minimum values (for each department) and then it is compared to the salary from the outer query?
>>
File: IMG_20170222_162118.jpg (3MB, 4160x3120px) Image search: [Google]
IMG_20170222_162118.jpg
3MB, 4160x3120px
Was looking to get started in Java (i posted the other day because I'm in construction) and was looking at these to get started (I found em nice and cheap at powells books and they look to be in very good condition) If I'm looking to get into a workplace how well do you think a start with these books would do?
>>
>>59071784
ASSEMBLY
>>
>>59071838
It's a bit late to ask now you've paid for them.

Personally, I would rather work in construction than write Java for a living.
>>
>>59071862
$7 in total, I don't plan on just sticking to Java, but I've heard its one of the easier ones to use to get into the workplace, and it can't pay worse than my near minimum wage 60 hours a week currently, which should free me up to move onto C, and maybe jump into languages like Python later on if it interests me.
>>
what do people even use external libraries for except for GUI/opengl and basic utilities (like loading files and such)? surely you do more interesting things than e.g. finding the max value in an array which don't have pre-written library functions for them?
>>
>>59071838
it'll be great anon. microsoft shills and haskell neckbeards like to shit on java but java is literally the #1 programming language and those books are great.
>>
>>59071838
Watch this
https://www.youtube.com/watch?v=WPvGqX-TXP0
>>
>>59071948
Doesn't that expect that you understand all the concepts and have an understanding of *some* programming language so that him explaining it in the way he does makes sense?
>>
void manageDictionnary(vector<string *> *dictionary, char *p){
for(int i = 0;i < *dictionary.size();i++){
if(*dictionary.at(i) == *p){
break;
}
}
*dictionary.push_back(new char(*p)); }


I keep getting
error C2228: left of '.size' must have class/struct/union
on this, what should I do?
>>
>>59071969
If you have never done programming read the books in their entirety.
>>
>>59071971
(*dictionary).size()

Also storing raw pointers in STL containers is generally a bad idea. And pass dictionary as a reference too, not raw-pointer.
>>
>>59072003
Plus that means you don't have to do (*dictionary).size() or dictionary->size()
>>
>>59071976
I've dabbled in C, but I haven't really gotten all the way through a book, but I am planning on devoting a good amount of time to it to get into a better work environment.
>>
>>59071969
he's explaining at a quick pace and not explaining things very thoroughly to a beginner. the video might be ok to get a very basic feel of it but you should go through the books for sure.
>>
>>59072048
But are the books I grabbed good or not? The $7 doesn't mean much to me if they're bad, but I've heard that specifically head first java is a good one, the other was just really cheap because they had a ton of the 6th edition books
>>
>59072073
UTF-8 is literally a superset of ASCII. Every valid ASCII string is automatically a valid UTF-8 string.
If the "conversion" cannot be done, you probably have an invalid ASCII string.
>>
>>59072134
Let me link that again, properly: >>59072073
>>
>>59072138
okay, I just don't know how people get asian characters or latin characters using sys argv with the bloody windows commandline. I've also read that it relies on your system locale,

I've visited pretty much every stackoverflow link in existence, ans everything fails.
>>
>>59070505
First one, though I'd move the static modifier to the end.
>>
>>59071971
char something[] = "test";
std::find_if(yourvector.begin(), yourvector.end(), [&] (std::string& s) {
if (s == std::string(something)) {
yourvector.push_back(something);
return true;
}
return false;
});

i've been trying to learn modern c++
>>
>>59072197
Link your code
>>
>>59072197
>windows
Found your problem.
>>
>>59072246
correction
std::find_if(yourvector.begin(), yourvector.end(), [&] (std::string& s) {
if (s == std::string(something)) {
yourvector.push_back(std::move(something));
return true;
}
return false;
});

i believe you're supposed to use std::move so something doesn't evaporate if it goes out of scope before the vector and so you're not making a copy?

please help
>>
>>59072249
import os, sys, re, urllib, urllib2, subprocess
import shutil
from shutil import copyfile


filenamepath = str(sys.argv[1])
print filenamepath
>>
>>59072307
Use Python 3.

Also what is up with your imports?

Finally, I suspect your redundant str() is the problem.
>>
>>59072307
>Dem imports
Drop the str
>>
>>59072347
>>59072369
same shit happens without the str. it's just not that simple guys, try to get it to work and you'll see.
>>
>>59070897
You also need good understanding of multivariate calc, linear algebra, and stats.
>>
>>59072394
I get this when I try to decode/encode it

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 11:
>>
>>59072394
Works fine for me, even with your crazy imports and your str().

Stop using Windows, start using Python 3.

>>59072427
This is literally a specific kind of bollocks that Python 3 was rolled out to fix.
>>
>>59072394
>>59072422
>>59072444
Works fine for me here as well.
Also filenamepath is sys.argv[0] and not [1].
Try that first.
>>
>>59072444
>This is literally a specific kind of bollocks that Python 3 was rolled out to fix.
yeah I get that but I'd have to rewrite my script

anyways, thanks guys
>>
>>59072477
no it's not for me, sys.argv[0] is the path to the script
>>
>>59072483
You'd have to add one pair of parentheses. Also check out '2to3', which will modify your script for you.
>>
>>59072003
Thanks.
>>
>>59072422
I have that.
>>
>>59072553
Then you're set.
>>
>>59072594
Any good resources?
I have older ML textbook but it feels out of date.
>>
template<typename T>
T Clamp(T min, T max, T val) {
if (val > max)
return max;
if (val < min)
return min;
return val;
}


void main(){
int x = 2;
int clamped_x = Clamp<int>(0,1, x);
}


is this what a template is? anything you call with a <>?
>>
>>59072644
Bishop? I've heard a lot of good about that one, but it's dated.

I liked reading Elements of Statistical Learning. The book is a free download from Stanford's website.

Honestly, though, it's such a moving target that you're probably better off reading research papers.
>>
>>59072677
Think of templates as a way to generalize functions. Consider some kind of container, like a binary search tree. Lets say you write your tree such that the nodes in the tree take Ints as their key. Now, your boss comes in and says they need to take strings. Do you go back and re-write all your BST code to use strings as keys? Nope, you can use templates to tell the compiler that the type you want to use for the key will be defined later, and thus you can abstract your code from any specific "type" that you would want to use for a key.

When you compile your code, it will look at what kind of BST's you need (<int>, <string>, <some kind of custom struct>, ect) and generate the appropriate BST class(es) with that type in place of the template parameter.
>>
>>59072706
Machine Learning by Tom Mitchell, it's from 97.
It's okay and I'm just using it for background mostly.
I didn't want to get bogged down reading papers for everything but some tutorials/guides I find are just "do some convolutions, majority pooling, and deep nets lol"
>>
>>59072821
I think you should start off with the basics. I know that was what got me into machine learning. Learning how neural networks worked, weight, biases, how they propagate, nodes etc. Unless you already know them then yeah start somewhere else. And read a lot of research papers.
>>
>>59071077
>Boris
my man
>>
>>59072821
http://neuralnetworksanddeeplearning.com/index.html

This site is pretty good. While CNN's just a single tool in the ML playbook, the website does derive SGD algorithm and mentions/derives a lot of important concepts like regularization and choosing hyper-parameters.

For books, try:

Artificial Intelligence: A Modern Approach
An Introduction to Statistical Learning: with Applications in R
The textbook I had for class written by my professor is also free, http://luthuli.cs.uiuc.edu/~daf/courses/LearningCourse17/learning-book-Jan-18-all-small.pdf
I liked it, but it's not for everyone.
>>
>>59072936

I've got Luger's AI book right, and it makes a nice addition to that list.

More heavily focused on AI than ML, especially, but good nonetheless.
>>
>>59073006

right now**, rather.
>>
>>59072936 (Me)
>>59073006

Things like Markov Chains/Simulations/HMMs are used in a huge variety of environments, from particle physics to finance, and I've found are covered mostly by AI books. If you want to see something REALLY cool check out:

http://karpathy.github.io/2015/05/21/rnn-effectiveness/
>>
>>59072936
I hear a lot of hype and buzz about NN are there other ML methods that are seeing as much use these days?
>>
>>59073089
No. NN are generally regarded as the most efficient barring experimental methods.
>>
>>59073089
SVMs, Regressions, EM, Hidden Markov Models, Random Forests, Nearest Neighbor are all in use.

It's more that until the past few years, deep NN's have been hard to train well due to lack of training data (that captcha that asks you to mark all squares for signs and what not is actually providing google with a labeled example for them to use), mathematical problems like gradient explosion/death (i.e. network fails to learn/learns prohibitively slowly), and computational problems (faster GPU's/CPU's, CNNs have considerably less parameters than 'normal' NN's) all of which are 'more solved' today.
>>
>>59073239
I'm seeing tutorials mention training times in the hours with new and multiple gpus.
Any hope with mediocre laptop?
>>
File: anim.webm (488KB, 1591x844px) Image search: [Google]
anim.webm
488KB, 1591x844px
>>59072916
check this out

i'm working on displaying album pages, all i have to do is show the list of tracks - the backend is ready, I just need a nice table
>>
>>59073253
maybe you can use amazons web services somehow?
>>
>>59073253
Check out the TensorFlow tutorial for the MNIST data set. The images used in the data set are fairly small. It's all in Python and easily to follow. Then, once it's ready to go, check out my first link in:

>>59072936

And try to build a network in TF like the basic CNN he builds. TF also has a GUI that will show you how your network is connected, it's really quite cool, but it will still take you awhile to train.
>>
I just heard my female flatmate use the toilet without wiping her minge
>>
>>59073280
That's awesome man, keep up the good work
>>
i wrote a bootloader in haskell but it broke my pc? like i press the power button and nothin fuckin happens...... wtf?
>>
File: programming-languages.jpg (129KB, 640x369px) Image search: [Google]
programming-languages.jpg
129KB, 640x369px
Reminder
>>
>>59073458
>Python and JavaScript better than C
I know this is a troll but I will fight you IRL
>>
>>59073473
The only reason to ever code in C in the year of the lord 2017 is if you are working with embedded system. Even now embedded systems are getting more and more memory and processing power that you can code in C++. Ask anyone who works with embedded devices if they want to code in C or a language of their choice, 100% of them will choose any other language.

t. Electrical Engineering Graduate
>>
>>59073530
I use C for GUI apps.
>>
>>59073530
fuck off dan
>>
>>59073566
I too like to make a bonfire when I make omelettes
>>
>>59073572
I don't know who is dan but I work in a job where I use PLECS all the time and have to interact with people who actually program in C for a living so I know what I am talking about.
>>
>>59073280
nice dude. I assume this is in a web browser and you're pulling (at least initially) the data from some API?
>>
>>59073586
it's actually really easy if you use SDL
>>
File: 1485262515835.jpg (76KB, 1065x859px) Image search: [Google]
1485262515835.jpg
76KB, 1065x859px
>>59073599
>I know somebody who programs in C
>Therefore I know everything about C, and all of the people that use it
>>
>>59073606
This is a desktop program

Info about albums is pulled from last.fm and musicbrainz

Now I'm working on finding the tracks from these albums in various sources.
>>
>>59073618
I know people who program in C for a living which is more than I can say for a basement dwelling NEET like you. I actually have a transcript that says I got A for modules pertaining to embedded systems.
>>
File: Leslie Lamport.jpg (38KB, 393x500px) Image search: [Google]
Leslie Lamport.jpg
38KB, 393x500px
You have been visited by 3x Dijkstra Prize recipient and inventor of LaTeX, Correctness Lamport.

Improved correctness, performance, and reliability of computer systems will be yours, but only if you reply to this post with the words "if you don't listen to this man, you're gonna screw up badly".
>>
Two of (new-ish) the junior developers in my team are pressuring the team lead to let them write some new utility in Rust. The entire codebase and common libraries are in C++. The email chain is currently at 49 replies.
>>
>>59073635
>I actually have a transcript that says I got A
Wow anon, we're all really impressed that you got an A. I don't think anyone else has ever done that before.
>>
>>59073635
Again, your "argument" is completely retarded.
Just because I know a pretty good chef, does that automatically mean that everything I say about cooking is correct?
>got A
Good for you, anon. I also got a lot of A's.
>>
>>59073642
Great guy https://www.youtube.com/watch?v=-4Yp3j_jk8Q
>>
>>59073678
I love his talks. Truly underrated.
>>
>>59073653
>>59073666
>Have a job that deals with entire departments of people programming in C
>Have experience programming in C
>Nah that doesn't count

I don't know a person. I know and interact with entire departments of people who work in C because I do circuit design for electronics. I work alongside people who program MC for the circuit boards I design. In a multinational company.

So please sit the fuck down kids.
>>
>>59073643
Tell them to get fucked and to stop triggering others.
>>
>>59073643
Just forward the email chain to management and tell them the manpower hours isn't worth it.
>>
>>59073701
You bragged about getting an A in one of your classes, anon. Come back after you graduate.
>>
>>59073701
Again, that doesn't mean shit. You're just spouting some stupid logical fallacy.
In highschool, I worked at a very successful supermarket. Does that mean that I everything I say about business management is correct?
>>
>tfw you are all plebs at programming who couldn't even solve how to reverse a binary tree
>>
>>59073735
I got A in my classes to prove I have experience with C retard. Did you miss the part where I graduated and am currently working? Stop being jealous.

>>59073736
>spouting some stupid logical fallacy.
>Compares a successful supermarket to a MNC
If you worked in the upper management of a successful supermarket then business management would hold weight.

I am not saying I am 100% correct but my opinions hold more weight and value then the two of you retards put together. But keep circlejerking about C on /dpt/ from your basements. Adults actually hold jobs.
>>
>>59073765
>tfw plebs think that working for the company that designed golang is something to aspire to
>>
>>59073765
what the FUCK look at my RESUME, I worked on HOMEBREW
>>
>>59073767
Did you get any other As? I did, and so did the other anon, so right now I think our credentials trump yours.
>>
File: smart.png (299KB, 680x598px) Image search: [Google]
smart.png
299KB, 680x598px
>>59073779
>tfw plebs actually think there is much of a difference using a specific language
>tfw to intelligent to get involved in programming language wars
>>
>>59073795
lel the butthurt was real with that one. he'll just never get it, will he, anon?
>>
>>59073821
All languages are Lisp in disguise.
>>
>>59073729
Snitches get stitches
>>
>>59073818
>I did, and so did the other anon
I have working experience and As. Graduate. Work a few years in a job with exposure to C programming then come back. Like I said, sit the fuck down.

Also I am an EE graduate so I am not sure why getting an A in signal processing will increase my credentials but w/e
>>
>>59073821
>tfw plebs think PHP and Agda are equally suited to theorem proving
>>
>>59073844
>tfw plebs think Lisp is the best programming language because of an outdated SICP book
>tfw real good programmers program in many different languages
>>
>>59073847
If you are going to code in an entirely different language, the project lead will have to notify the managers sooner or later. Pick the winning side early than die a wronged death when management comes breathing down your necks asking who the fuck started this.
>>
>>59073868
All of which are Lisps.
>>
>>59073854
>Graduate. Work a few years in a job with exposure to C programming
Already done that.

Come back when you have a few years of experience with other languages too, because until then your opinions will continue to be woefully uninformed.
>>
>>59073767
>I got A in my classes to prove I have experience with C retard
That doesn't mean shit.
Lets go over some pretty basic C things to see how knowledgeable you are, then. Obviously, you should be able to answer these without looking them up, or compiling and running the code.
How do you declare a function to return a function pointer, without using a typedef?
What is sizeof(int)?
Describe the bug(s) in this function:
int my_strlen(const char *str)
{
int ret = 0;

while (*str++)
++ret;

return ret;
}

Describe the bug(s) in this program:
#include <stdio.h>
#include <signal.h>

int finished;

void handler(int sig)
{
printf("Recieved signal! Exiting...\n");
finished = 1;
}

int main()
{
signal(SIGINT, handler);

while (!finished);
}
>>
>>59073895
>Already done that.
Funny because you never once mentioned that anything about that. Maybe that is because you are making shit up. So if C is so good, please tell us your job and what you do.

>>59073900
Hey CS undergrad, your "knowledge" impresses no one. Maybe you are so defensive because C is being forced onto you and you have no choice.
>>
>>59073924
This is some basic shit. If you don't know these, you are definitely NOT experienced in C.
>>
>>59073928
>This is some basic shit
Exactly and what is that supposed to prove retard?
That I can do C? And? Because even if I answer them correctly, you are going to just throw more pointless shit at me till you stump me. I ain't got time to play stupid games with stupid people like you. You don't want to listen to me? Fine. Don't pretend your bullshit will trip me up.
>>
>>59073948
Just answer the fucking questions. You're clearly just trying to dodge it.
This isn't obscure shit I'm asking you.
>>
>>59073948
>You don't want to listen to me?
Why would we, when your posts thus far have been neither insightful nor interesting?
>>
>>59073967
What is the end game to answering your question?
I browse /dpt/ enough to know your kind. I have answered plenty of questions right in the past. But your kind will never admit it, that I am right. Instead you will throw more questions at me or nitpick my answer to "discredit" me. I have never seen a single argument on /dpt/ where someone goes
>Prove you know X language answer this
>Person answers correctly
>Oh I admit I was wrong sorry.
Never.

>>59073972
Then don't reply to my post dipshits. All I did was input my working experiences and you all C monkeys start clamoring out of the basement to defend your shit language.
>>
File: 1437758775656.jpg (40KB, 535x577px) Image search: [Google]
1437758775656.jpg
40KB, 535x577px
I just want a good job.
What do you do, how long have you been working, and how much do you make?
>>
>>59073900
a C int is 32 bits/4 bytes
*str++ will go out of bounds on the last iteration
syntax error in the signal call regarding the function (passing in a function name)

these are the easiest fucking questions in the world. You're outing yourself as someone in compsci 101 with the sizeof(int) question.
t. a C++ guy
>>
>>59073620
Is this in WPF?
>>
>>59074020
Freelance.
>>
>>59074013
I don't even like C, I'm just posting because you're wrong.
>>
Does anyone else program high? I find that working on my own I tend to do better high, but in class I can't solve problems as well.
>>
>>59074036
All of your answers are incorrect.
>>
>>59074036
Wrong! You may wish to study C.
>>
>>59074045
You're going to have a hard time doing that when you have a job.
>>
File: insulting bait.png (23KB, 625x626px) Image search: [Google]
insulting bait.png
23KB, 625x626px
>>59073458
>High tier: JavaScript
>Low tier: C
>Shit tier: Lisp
>>
>>59074013
>to "discredit" me
Yes, I was trying to discredit you, and it fucking worked.
You clearly don't know anything about C.
>I have never seen a single argument on /dpt/ where someone goes
I have. There is sometimes meaningful discussion that actually goes on here.
>>
>>59074041
>I'm just posting because you're wrong
Why am I wrong? I work with entire departments of people that code in C. I sit in during meeting listening to the head of design who has decades of C programming experience. I sit with him in the cafeteria at lunch and talk with him. R&D department comprises of multiple engineering people who code in C. Tell me why am I wrong.
>>
>>59074060
If Lisp is shit tier, then every language is shit. I cracked it guys!
>>
Learning C, I came at a good time. Just curious if anyone can show me examples of doing bad things with pointers. Like accessing things with pointers you should not be able to access without using pointers as a work around.

Also would a compiler yell at me if I did something like that? Thanks.
>>
>>59074054
i see you like games
find bug in my shitty code instead:

void reverse(char *s) {
char *sp = s, *ep = s;
while (*++ep != '\0');
ep--;
while (sp < ep) {
if (sp != ep) {
*sp++ ^= *ep-- ^= *sp ^= *ep;
}}
}
>>
>>59074065
Nah I ain't got time for monkey games with you and your >muh bugs please figure out because people like you will never admit you are wrong. Good luck finding a job after you graduate from compsci.
>>
>>59074072
>I work with entire departments of people that code in C. I sit in during meeting listening to the head of design who has decades of C programming experience. I sit with him in the cafeteria at lunch and talk with him. R&D department comprises of multiple engineering people who code in C.
So what? None of that means you know C. You may wish to consider your arguments more carefully before posting them.
>>
File: omg i love BSODs.jpg (242KB, 495x600px) Image search: [Google]
omg i love BSODs.jpg
242KB, 495x600px
what are some C language features that you abuse on a regular basis?
if ((ctx = queue_state(&worker[i]))->status != STATUS_OK)
>>
C is shit and should ONLY be used to interface with hardware.
C# is alright.
C++ is god.
>>
>>59073900
Not the autist, but I wanna try:
I have used FP's in C all of twice. I know how to declare them (for use in a file system), but to return? Had to look it up =( Woulda never got it.
sizeof(int) is platform dependent, but usually 2 or 4 (i.e. number of bytes to hold 'int' type).
First function, walking off the end of the string like that is undefined behavior, thus could hold data for another string ect and return incorrect length.
Second function I am less sure about. Finished is global and usually init'd to 0, but I could see issues race conditions -> infinite loop. I would guess you would need to define finished as volatile?
>>
>>59074101
What code? I don't see any code in your post.
>>
>>59074135
C# is shit and should ONLY be used to interface with morons.
C++ is alright.
C is god.
>>
>>59074110
>Works entails PLECS
>You don't know C
Yes. Anon I am hired to do something I don't know.

>You may wish to consider your arguments more carefully before posting them.
Which is already more than I can say for you since from the very start your arguments can be summarized in two words.
>LOL
>No
>>
>>59074144
>sizeof(int) is platform dependent, but usually 2 or 4 (i.e. number of bytes to hold 'int' type).
Correct. It's implementation defined, but guaranteed to be at least 16 bits.
>First function, walking off the end of the string like that is undefined behavior, thus could hold data for another string ect and return incorrect length.
Incorrect. Having a pointer point 1-past the end of an array is explicitly allowed, and it is never accessed.
>I would guess you would need to define finished as volatile
That's one of the bugs, but there is more than just that.
>>
>>59074147
t. Undergrad or unemployed "developer"
>>
since we're arguing about C in this thread, can someone help me understand string literals and character arrays?

So for example, let's say I have a function:

int foo (char *string1, char *string2) {

/*do something and edit string2*/

}



What does it look like in memory when I do something like this?

int main (){

char string2input[50];
foo ("hello", char *input)

}


How can I access string2input/string2 once I'm instead the foo method?
>>
>>59074180
t. enterprise "developer"
>>
>>59074181
oh fuck, that second block of code is supposed to look like:

int main (){

char string2input[50];
foo ("hello", string2input);

}
>>
>>59074157
I wager you know about as much C as the company receptionist does.
>>
>>59074188
Yes enterprise developer is a job. What is your point? Being an undergrad or unemployed is better? Sometimes /dpt/ can be so stupid where they think saying someone with a job is an proper comeback to an unemployed diss.
>>
>>59074211
Look more LOL no arguments. Hey.
>You may wish to consider your arguments more carefully before posting them.
>>
>>59074181
>>59074199
A string literal in C is stored statically in memory. You're not allowed to modify this memory.
You can think of it like this:
int main (){

char string2input[50];
static const char literal[6] = {'h', 'e', 'l', 'l', 'o', '\0'};
foo (literal, string2input);

}

(The array notation is used jut to be explicit. You can do it more concisely in C)
So that's why you can treat a string literal just like a pointer.
>>
>>59074215
hahaha i'm just messing with you buddy, no need to get your panties in a bunch
>>
>>59074225
Still no evidence that you know more than a smidgen of a gnat of C.
>>
>>59074145
>can't into programming, pick on muh formatting intead
though so
>>
>>59074231
also, a string literal is reduced to a pointer to readonly memory, so you can do stupid shit like "123467890ABCDEF"[num & 0b1111] and it'll be fully accessible like an array
>>
>>59074135
>C is shit and should ONLY be used to interface with hardware.
you can interface with hardware just fine in C++ which makes C completely obsolete.
>>
>>59074233
>Haha I am only pretending to be retarded
>>
>>59074121
What are u abusing here? Thats like 5 lines of basic assembly.

>>59074135
>>59074147
C# is like being a virgin and paying for a model hooker, after that u become god
C++ is like fucking your girlfriend while your dad is watching. (do you really need RAII anon? delete 2 hard 4 you ?)
C is godmode, its literally like having a 50cm dick
>>
>>59074251
>can't even format posts on 4chan
>>
>/dpt/ fags constantly bitch and moan about any language that isn't C
>that's the extent of it - they don't post their own code, they don't have jobs, they don't even program; they just sit here and suck each others dicks over a language thats suboptimal for what they're trying to accomplish (if they wrote code)

lol faggots
>>
>>59074244
Okay friendo whatever you say. Now go graduate and find a job in C programming k?
>>
is______this_____shit____still_____a____fucking____thing____in____python?

I want to use Python, but this shit makes me sperg out.
>>
>>59074258
feel free to believe whatever you want, friendo
>>
>>59074276
Like I said, been there done that pal, one day you'll catch up ^.~
>>
>>59074082
shameless bump for wisdom
>>
>>59074257
Yeah enjoy dragging that piece of shit std lib
>>
>>59074290
>been there done that pal
>implications
>>
>>59074257
I love taking every opportunity I can to state C++'s general superiority over C, especially in team environments, but you're nuts if you think C++ interfaces as well as straight C with most hardware.
>>
>>59074255
>a string literal is reduced to a pointer to readonly memory
Just to be pedantic, that's not actually true. An array is typed to be an array of the correct size. So "hello" is char[6], not a char *.
The arrays almost always decay into pointers when used, but it will produce a different effect if you use sizeof on a string literal, and a few other things.
>>
>>59074296
*((int*)0) = 1;
>>
>>59074082
>>59074296
If you ever find yourself casting between pointer types, you're probably doing something horribly wrong.
>>
>>59074270
Don't forget
>If you question their language, they sperg out and proceed to go off tangent and post code for you to bug fix
>>
I'm trying to make minesweeper in java but I hit a wall trying to do two things.

I have two arrays called mn[row][column] (boolean) & minedneighbours(int) which represents the minefield & the number of neighbouring squares which contains mines for each squares.

I want to ask how to:
A) create a method with row & column param, which set the tile that will be mined & then increments the neighbouring total of the surrounding tiles using a for loop.
It should return true if the mile is mined & false if the max num of mines is exceeded or the square is already mined.

B) A toString method which retruns a string that represents the minefield. '*' will represent the mines & the num of neighbouring mines for unmined tiles. For example:
00011212*1
0112*3*532
02*434***1
03**3*4*31
02*6*32110
023**20000
01*3222210
122212**10
1*11*21210
0000000000
>>
>>59074270
>he says as he does none of the things he listed
>>
>>59074302
>received the exact same amount of proof and evidence as he gave
>>
>>59074231
>>59074255
thanks anon

what about the uninitialized character array? When you pass it into the foo function -
int foo (char *string1, char *string2) {

/*do something and edit string2*/

}


*string2 points to the empty/uninitialized array? Is that correct? How can I edit what is in that array? Would I have to make my own character array in the method and then have *string2 point to it?
>>
>>59074306
This is basically it. C interfaces better with hardware. But people here always think otherwise. Unless you are working with embedded devices, C is fucking pointless.
>>
>>59074322
Whats wrong with casting between pointer types?
is your brain unable to handle that? are u going to hit me with Rust/salary sperg shit again?
>>
>>59074336
>*string2 points to the empty/uninitialized array?

and by this I mean the "start" of the that block in memory
>>
>>59074277
You get used to it

Besides, you only use two __ at most for functions like __init__(self) or __repr__(self) in classes

Maybe I"m full of shit, but with python, this looks cleaner;
>>
>>59073900
>How do you declare a function to return a function pointer, without using a typedef?
I'll admit this is one I don't know, I only got so far as knowing that it involves an asterisk in front of the function name, and enclosing the function name and the asterisk in a set of parentheses.

>What is sizeof(int)?
Implementation defined, but guaranteed to be at least 2 bytes, and no smaller than sizeof(short).

>Describe the bug(s) in this function:
You're incrementing the value POINTED TO by the pointer, rather than the value of the pointer itself. In addition to not being the obviously intended behavior, it's also illegal since the pointer is defined as a pointer to constant (i.e. read-only) data.

While not a bug, the way you use whitespace for the "++ret" statement is a bad idea, since it encourages "goto fail" type errors if anyone was to add something else to the body of the while statement.

>Describe the bug(s) in this program:
main() specifies no return value, which I believe is undefined behavior in some versions of the C standard.

"int finished" LOOKS like undefined behavior, but it isn't; global variables are guaranteed to be initialized to 0 or equivalent.

Other than that, I don't SEE any obvious errors, though I'm not very familiar with the signal header.
>>
>>59074276
What do you write out of curiosity? Or what are you advocating?
>>
>>59074333
>Implying I am going to take a picture of my company pass for spergs like you
Okay anon. Good luck finding a job and when you do good job working in the embedded system field.
>>
>>59074306
How so? What does C have that C++ doesn't?
>>
>>59074346
I just hate it and the mandatory spacing. I honestly have more fun coding in Swift than Python. Swift was actually f-f-f-fun.
>>
>>59074353
>i dont believe u but u should totally believe me k
>>
>>59074336
>>59074345
>*string2 points to the empty/uninitialized array? Is that correct?
>and by this I mean the "start" of the that block in memory
Right.
>How can I edit what is in that array?
Just write over the values like you would with a normal array.
Reading the uninitialised values is something you don't want to do.
>Would I have to make my own character array in the method and then have *string2 point to it?
This is getting into the realms of dynamic memory, which I can't be bothered explaining.
Just keep going with whatever thing you're using to learn C, and they will explain that.
>>
in haskell this is just

let mode = head . maximumBy (\x y -> length x `compare` length y) . group . sort
>>
>>59074350
I work in circuit design. PLECS.

>What are you advocating?
That the only reason people use C is because it is required for embedded systems and given a choice they would prefer to use any other language of their choosing.

>>59074360
You don't have to. It is a fact that majority of C jobs are in the field of embedded devices and systems.
>>
>>59074370
ruby ruby ruby ruby
>>
>>59074338
How is C pointless? It gives highest performance and lowest abstraction/overhead possible in a language. Every proper lib is written in C. C++ development nowadays is just importing Qt/boost and 50 other templated abstraction libs with Chromium/Awesomium.

Do you really need to drag all that shit just to make a http get req (looking at you QtNetworking/libcurl/OpenSsl)

>daily reminder using libs/general abstractions is not programming.
>>
>>59074325
The toString() should be easy. For loop with an inner for loop, checking a position each iteration and appending to the strBuilder/strBuffer. After the inner loop is done, append a '\n'.
>>
>>59074375
I USE C BY CHOICE
>>
>>59074313
can you explain? you set 0x00000 to 1? but why..
>>
>>59074382
Alright go ahead and name fields and industries that use C. And then consider the fields that don't use C. What is the difference?
>>
>>59073876
No chance it'll go anywhere, even with their pestering. Team Lead's a veteran. He did programming at Mastercard back in the day before they used C, before they even machine compiled their programs. I'm pretty sure he's not going to let them go forward with it.
>>
>>59074400
You wanted examples of doing bad things with pointers, I gave you one.
>>
>>59074380

in ruby this is just

def mode(lst)
lst.group_by{|x| x}.max_by{ |k,v| v.size }[0]
end
>>
>>59074270
Lisp
>>
>>59071784
Anon. You're in luck. When I was learning this resources were scarce.
I'd recommend handmade hero. It's a 'write a game from scratch' series which aims to use libraries as little as possible. Made by an experienced game engine programmer.
Now maybe you don't want to make a game. All that means is that theres a bunch of filler in the series you don't really care about.

It teaches you a good attitude towards programming portable systems and has focus on understanding that the code you write is meant to be malleable.

Common complaints are things like him starting with learning you the fixed function opengl pipeline. But it's done to give a more clear understanding of the principles involved rather than teaching you best practice so you can ape it. Next weekend he has said to move to the modern pipeline with shaders and such.
>>
>>59074421
No I mean Ruby the poster who pretends to be a man
>>
>>59074424
He's been broadcasting every fucking day for 2 years and he still hasn't touched modern GL?
>>
>>59074433

Ruby is a man. A gay man.
>>
>>59074404
Scientific/Research/Gamedev/Embedded

Fields that dont use C are all filled with brainlets reaping monkeys and caring about 1 second long animations so GUI looks good.


Have you ever benchmarked C&ASM vs C++ ? The performance gain is insane. If i had to pick between $200k writing C++ using libs or optimizing memmem for the rest of my life in a prison i'd always pick memmem optimization
>>
>>59074415
Then why the fuck did the Team Lead let the email chain go on for so long. If your team lead is letting junior fucking developers have this much leeway, your team lead isn't really good at leading.
>>
>>59070897
Actually, I would also like to get into ML. I'm taking the Deep Learning course at Udacity and am enjoying it a lot. Only thing is college gets in the way a LOT. Anyone have any advice for someone picking up web dev as a profession? inb4 learn react
>>
>>59074375
What's wrong with embedded systems? It pays well. It's not particularly difficult. You get to work with cool people who know actual things and not just how to monkey with computers.
>>
File: 1459376274332.jpg (427KB, 1920x1080px) Image search: [Google]
1459376274332.jpg
427KB, 1920x1080px
I am a compsci major, we are learning using C++. We just finished covering structures and classes. I have K&R, read parts related to what we're learning and also read the C++ book we are using. What projects could I work on in my free time to get gud at programming? I'm particularly interested in eventually doing some network programming (starting simple) or Unix programming. Am I getting too far ahead of myself? I love Linux, have been using it for around 6 years now.
>>
>>59074447
Ruby is a woman, everyone on /dpt/ is a woman pretending to be a man (some of them pretend to be men pretending to be women).
>>
>>59074364
thanks anon I appreciate it
>>
>>59074448
>Scientific/Research

A lot of scientific/research computing is still on Fortran, though.
>>
>>59074444
The breath he has gone through is impressive though.
Of course you could easily go for modern opengl quicker than he has but he's gone through more important things imo.
>>
>>59074144
>>59074168
I am not really sure about the second function, it might be that it is not portable. I know that *str++ == *(str++), i.e. the object itself is not incremented, and that const char * str is a pointer to a const char.

The other problem for the third is no return type.
>>
>>59074465
>everyone on /dpt/ is a woman pretending to be a man
>implying
no, anon, we're all cute lolis pretending be boys. get your shit together.
D A BEST
>>
>>59074347
>I'll admit this is one I don't know, I only got so far as knowing that it involves an asterisk in front of the function name, and enclosing the function name and the asterisk in a set of parentheses.
A function with no arguments, returning a pointer to a function returning an int, taking 2 ints as arguments:
int (*my_fn(void))(int, int);


>but guaranteed to be at least 2 bytes
Technically not true, but you got the implementation-defined gist of it.
It's conceivable for an implementation to have CHAR_BIT == 16 and sizeof(int) == 1.

>You're incrementing the value POINTED TO by the pointer
No it's not. The increment operator has a higher precedence than the dereference operator.

The actual bug in the function is that it returns an int for the size of something.
size_t is the correct type that should have been used, and an int can overflow for large strings.

>main() specifies no return value
It's well-defined to implicitly return 0 in C99 onwards.
>"int finished" LOOKS like undefined behavior, but it isn't; global variables are guaranteed to be initialized to 0
Right.

There are 3 bugs in that program.
First, 'int' is the wrong type. It should be sig_atomic_t, which is one of the few types which is safe to access from a signal handler. (sig_atomic_t might be a typedef for int, but that is not portable).
Second, finished should be volatile. Another thing to do with signal handers.
Third, it calls printf from inside the signal handler, which is not safe to do. There are very few functions which are actually safe to call from a signal handler, but I can't be bothered looking up and listing them off right now.
>>
Daily Reminder

/dpt/ cannot into OOP
>>
so /g/, why does the following code work (aka finds open port 80):

import socket

target = "4chan.org"

def pscan(port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)
s.connect((target, port))
return 1
except:
return 0

for p in range(1, 100):
if pscan(p):
print "[*] Port %i open" % p
else:
print "[*] Trying Port %i..." % p


but this one does not:

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)


I initially thought that the second approach would be faster because we don't have to create a new socket object each time we call pscan.

why do i have to create 's' freshly before connecting?
>>
>>59074455
Nothing. But given the choice those people working with embedded systems would always work with something else but the nature of their job means they have to use C. Whenever a project comes up and the idea of using C++ is floated, everyone fucking votes for it even if it ends up going nowhere. When it is your job, you are not looking at performance or what not, you are looking at comfort and ease of use. That is basically my point, people use C because they have to in this field not because they want to.

>>59074448
>Scientific/Research
Ruby. Fortran. Python. Good luck finding a job in that field that requires C. Even if you know C, it isn't a high advantage since it is for science and research. Unless your research entails low level programming which goes back to embedded systems.

>Gamedev
What games are coded in C?
>>
>>59072133
Head first is decent. Just stick to it and write some of your own programs implementing the concepts you learn after each chapter. I haven't learned from the book but the key is just sticking to it. You'll be fine, anon.
>>
>>59074493
>The other problem for the third is no return type.
Not an error in C.
>>
>>59074511

sry.. fucked up second snippet..

here you go:

import socket

target = "4chan.org"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)

def pscan(port):
try:
s.connect((target, port))
return 1
except:
return 0

for p in range(1, 100):
if pscan(p):
print "[*] Port %i open" % p
else:
print "[*] Trying Port %i..." % p
>>
What's the best way to get into web development as a profession? I honestly just wanna ditch my shitty community college and really get hands on with the stuff. I know freelance is an option but I'm struggling to see how I will find clients in my town, much less what they will need. I live in southern Texas btw.
>>
>>59074462
Unix network programming will be a thing of the past in 5-10 years.
But I'd say it's still worth learning. It's not difficult. It's elegant in certain ways and it may help you design systems well in the future.
I think as long as you ensure that you understand what you're doing you're not getting too far ahead of yourself.
>>
>>59074036
>a C int is 32 bits/4 bytes
Nope, it's implementation defined, all that's guaranteed is that it's at least 2 bytes (where a "byte" is however big a char is), not smaller than a short, and not bigger than a long. (it's perfectly legal for int, short, and long to be the same size).

>*str++ will go out of bounds on the last iteration
Not really, since it's postfix increment the dereference operator doesn't operate on the incremented value, so the invalid pointer will never be dereferenced. It will end with the pointer pointing beyond the legal memory (assuming the null character is in the last element of the array), but that's perfectly legal as long as you don't dereference it.

>syntax error in the signal call regarding the function (passing in a function name)
Nope, it expects a function pointer, and simply using the function name (without any function-call parentheses) is a valid way of passing the address of a function.

>>59074135
Every non-trivial program involves interfacing with hardware.

>>59074251
If you want people to be able to understand your code, try to at least make it readable. YOU wouldn't want to debug code that looks like that, would you? C is a structured language, and the programmer's job is way easier if your code allows you to see the structure.

>>59074257
The useful low-level subset of C++ is basically C with a more powerful macro system added.

>>59074313
Undefined behavior.
>>
>>59074549
>Undefined behavior.
I know, that's why it's a bad thing to do with pointers.
>>
>>59074354
marginally more explicit, easily translatable to assembly, leaves no room for errors

>>59074382
C++ is massively more popular, more used, and pays better in general. Development in C++ is much more than "just importing Qt/boost..."

>>59074462
Write implementations of all the data structures you can, in as many ways as you can (vector with extendable array/circular extendable array/linked list, etc).

Streamline them as much as possible while maintaining good structure (ie refrain from using gotos). Document important algorithms and their complexity.

Post it all on github, reference it in interviews/applications.
>>
>>59074545
Try /wdg/ instead of here. People here look down on web developers.
>>
>>59073900

??? Think (*foo)(); is function pointer, unsure return.
I think that's compiler dependent on CPU word length.
Is that operator precedence shenanigans?
Never used signal before. Is it mutex/semaphore/interrupt stuff? Maybe problem because printf() is probably not reentrant.

How much do I need to get an entry job in embedded? I can write out a driver for stuff like an ILI9320, read datasheets, setup peripherals and interrupts. But I don't have much knowledge of CS stuff like data structures, algorithms, and recursion. Would a hobby project were I did everything from scratch be enough proof? Feel like interviews are going to be some nerd asking you trick questions to catch you off-guard.
>>
>>59074545
Follow the memes.

Also try looking in Austin.
>>
>>59073900
This is embarrassing..
>>
>>59074516
>What games are coded in C?
Everything before 1998
As for the modern day, there's not a single notable game written in C
>>
>>59074575
>>59074587
Thanks for the advice friends :) Honestly I just wanna work in web development until I learn enough to get into ML.
>>
>>59074506
Should I learn OOP?
Can one get a job without properly knowing OOP?
>>
>>59074549
>every non trivial program involves interfacing with hardware
Depends. I find tons of network code to be very much non-trivial but it rarely interfaces with hardware directly.

In general yeah probably.
>>
>>59074450
Good point -- I'll tell management :)
>>
>>59074591
Yes so Gamedev industries don't use C anymore and moved on to other languages despite C giving "highest performance and lowest abstraction/overhead possible in a language". Why?
>>
>>59074619
Unity uses C
>>
>>59074619
Lack of skilled C programmers.
>>
>>59074511
>>59074536
My guess:
- First snippet opens 99 new connections by creating a new socket each time
- Second snippet tries to make 99 connections on one socket without disconnecting first

In your second snippet, try adding "s.close()" after the two print statements
>>
>>59074614
>Should I learn OOP?
Yes
>Can one get a job without properly knowing OOP?
Yes
>>
>>59074616
Snitches get stitches
>>
Why is stuff like posting and checking ban status in PHP or SQL? Would it be possible to do in JavaScript?
>>
>>59074614
CLOS
>>
>>59074549
>Every non-trivial program involves interfacing with hardware.
C fags, everyone
>>
>>59074546
Thank you for the input. I would ask questions about program structure but I think I should learn more on my own first
>>59074571
>Write implementations of all the data[...]
Alright. What would you consider an important algorithm? I learn about complexity (big O notation?) later this semester
>>
>>59074626
Game engine developer =/= Game developer.

>>59074627
Bullshit. Compsci courses generate tons of C fanatics. You only have to look at this thread for people thinking C is the best language in the world. Not saying they are skilled but Compsci courses generate tons of people willing to code in C.
>>
>>59074504
Why is printf unsafe to call? Is it due to the fact we could mess with a waiting threads buffer if it got interrupted in the middle of writing to stdout?
>>
>>59074619
It's a cultural thing. Expressed very well in Mike Actons Cppcon14 talk (q&a).
It's worth a watch if you wish to understand what major gamedevs concerns are.
>>
>>59074400
Traditionally, memory address 0 was used as what C calls the NULL pointer (i.e. a memory address that is guaranteed not to contain anything valid). This isn't true on all systems, however C uses a pointer value of 0 for the NULL pointer constant, translated at compile time to the ACTUAL null pointer constant on your system (i.e., if your system uses memory address 0x1111 as the null pointer, all occurences of the literal 0 in a pointer context are replaced with 0x1111.

Basically what the posted code does is cast the literal 0 to a pointer-to-integer, dereference it, and assign the literal 1 to that memory location. This is guaranteed to translate as writing through a NULL pointer, which is undefined behavior, and will usually cause a segfault.

>>59074506
OOP is codeword for bloat.
>>
>>59074549
>to understand your code, try to at least make it readable
well i wouldn't want to read dicks bragging their basic c knowledge in front of noobs either, but we live in an imperfect world.

c is also free-form and the code is pretty straight forward, there's nothing to format
>>
>>59074659
>Is it due to the fact we could mess with a waiting threads buffer if it got interrupted in the middle of writing to stdout?
That's the gist of it. A signal could happen inside the middle of a call to a standard library function, and that could cause all sorts of weird shit to happen.
It's basically a race-condition.
>>
>>59074656
most game developers use Unity it is very popular.. anon
>>
>>59074661
>It's a cultural thing
Yes. It is a cultural thing that people prefer to take the lazier path sacrificing minor benefits if they can get away with it. If tomorrow a language comes up that is basically English at the cost of non critical performances issues, every industry which could switch to it would.
>>
>>59074663
It's free-form with regards to the compiler and language specification, but it's much easier for humans to read if you use indentation to help make blocks identifiable.
>>
>>59074653
>ask about program structure
Well. If you ever do that in the future you should know that there's a lot of dogma in programming. People will tell you what's wrong and right for what's next to religious reasons. So you really have to take everything with a grain of salt and try the recommendations for yourself and verify if they seem as productive as people claim.
>>
>>59074683
So which games are coded in C?
>>
>>59074656
My CS course generated lots of FP fanatics, but I don't think there were any C or C++ fanatics at the end of it.
>>
>>59074703
So where are these C fags in this thread coming from? Because clearly they don't have a job programming in C.
>>
So i know basics of oop (java and c++) from university, but i want to take my knowledge to the next level, what do? Also man i am so uncreative with what to do. The /g/ image of "challenges" arent very challening either
>>
>>59074653
important algorithms are just algorithms that can be efficient and aren't obvious or intuitive, especially to non-programmers. For example:
algorithms to traverse binary trees
algorithms to bubble heap nodes up/down
Constructing a heap from an array/container of known size
inserting/removing data in a sequential structure that isn't on the ends
sorting data

etc etc
>>
>>59074619
Because Simula-style OOP is a good fit for simulations, at least as far as correctness goes. The zero-cost abstractions and STL are a bonus. Performance wise it's good enough. When "good enough" isn't good enough, and you need to squeeze every last drop of performance juice out of your program / machine; that's when you start to cleave away idiomatic OOP code and turn it into a whole different flavour of code. I've heard it called data-driven or data-oriented. To me it always looks like classic Fortran.
>>
>>59074711
>but i want to take my knowledge to the next level
Definitely start by nothing asking here because maybe one anon will answer your question while 10 more will go
>Java
>C++
and tell you to go learn X language instead.
>>
void LinkedList::append(std::string name, std::string occupation){
Node* addNode;
if(this->headptr == nullptr){
addNode = new Node(this->headptr,this->tailptr,name,occupation);
this->headptr = new Node(nullptr,addNode);
this->tailptr = new Node(addNode,nullptr);
}
else{
addNode = new Node(this->tailptr->prev,this->tailptr,name,occupation);
this->tailptr->prev->next = addNode;
this->tailptr->prev = addNode;
}
}


Hello friends. I am trying to implement a Linked List in C++ by myself. Valgrind is saying that there is a memory leak within the append method. I tried to figure out what it was but I couldn't find it. Any tips?
>>
>>59074629

thank your, sounds logical to me.

but your suggestion does not seem to fix it..
>>
>>59074687
Well I referenced a good source.
Another way of expressing what I said more clearly is that C++ is necessary because universities teach students that that'd what you have to use to do performance oriented code. Yet the gamedevs who care about that tend to avoid most of the features in the language.
See questions like
>>59074698
Are completely irrelevant. C++ is more than the technical categorisation of what language a piece of code belongs to. If you write C++ that's next to identical to C but you do it in C++ and abide by the rules of that language that's technically C++ and a game written like that is technically C++. But it's really designed as C code.
>>
>>59074722
So basically people don't like to code in C and only code in C when they are have to or are forced to?
>>
>>59074708
I sell game cheats made in C and ASM. Also I write my own drivers to bypass anticheats made by nigger cattle working at some company writing C++. The lols I have when I see debug strings inside drivers/game executables. Oh my
>>
>>59074760
I USE C BY CHOICE I HAVE ALREADY SAID THIS
>>
What's a good Haskell book for someone new to functional programming?
>>
>>59074777
I too want to be unemployed or an undergrad
>>
>>59074711
Take a data structures class. This is hands down the most constructive way to learn the benefits of OOP. Then generics/templates.

I'd recommend taking Java classes for this over C++ due to C++'s overhead in knowledge required. Losing out on pointers sucks though
>>
>>59074779
Learn you a Haskell for great good. It's free and a good INTRO to FP/Haskell.
>>
>had a phone interview for internship today, didn't get interviewers emails explicitly
>company follows [email protected]
>want to send thank you follow up

In this case, would it be best to mail something to them (they are 1 hour away), or email them and hope it's not creepy/it gets to the right people?
>>
>>59074789
>oop and datastructures
Sounds like you're really talking about the benefits of dynamic dispatch.
I doubt you really understand the implications but it's not actually about Oop at that point. You're probably talking about the benefits of polymorphism not object oriented programming.
>>
>>59074786
I'm neither, I use C for my hobby projects and an enterprise memelang for work.

>>59074802
No.
>>
>>59074816
Just make sure the information gets to the right place. If the place is big enough call the receptionist and ask for the email address you need.
>>
>>59074816
You could email reception/front desk/whatever and ask them to pass a message along.
>>
>>59074833
So C doesn't pay your bills but the enterprise memelang does? Not sure which is the real memelang here then.
>>
holy shit c++ is awful
>>
>>59074846
Something doesn't stop being a meme just because lots of people fall for it, Anon.
>>
>>59074846
>corporate people know what's best
Is there seriously people who consider this an argument?

There's no doubt C programmers get their bills paid. It's been the biggest language until C++ took over some time in the late 00's.
>>
>>59074761
Not surprised. Majority of code nowadays are written by H1B1 pajeets or college interns. Any anti cheat exist as a bare minimum for companies. Having a good anti cheat doesn't translate into more profit on paper so companies just do the bare minimum. I mean I am shit at programming and I can even bypass the VAC if I want to.
>>
File: CKtFM_nUEAAXaHa.jpg large.jpg (65KB, 768x1024px) Image search: [Google]
CKtFM_nUEAAXaHa.jpg large.jpg
65KB, 768x1024px
C++: The Good Parts
>>
>>59074397
Do you care to elaborate more, please?
I'm not sure that I completely get the toString() method at all or appending to strBuilder/strBuffer.

Thanks
>>
>>59074882
League of Legends had 3 MD5 hashes and ran a check through loaded dlls for ~ 5 years. Now the biggest anticheat (Elobuddy) loads entire CLR into the process and they can't detect it.
>>
>>59074882
>I bypass vac if I want
How? Just the broad picture anon. What's the plan?
>>
>>59074802
Will check it out.
>>
>>59074865
And now C programmers are mostly left in the embedded field and most probably would use C++ if they could.

Saying C is the best is like saying UK is the best because they used to rule an empire where the sun never set.

People who cling onto C and refuse to move on are just sad.
>>
>>59074846

McBiz needs steady amount of pajeets to write boilerplate and pajeets need to be replaceable. so that when one pajeet falls, you can replace with other pajeet. pajeets are widely available and cheap in memelang. little amount of C pajeets and the ones available cost too much, bad for McBiz
>>
Daily reminder that networking lib in .NET threw exception ( 150k cycles cost) if HTTP response wasnt 200 OK.
>>59074916
>>
>>59074916
And yet you work in a place with memelang. Are you pajeet?
>>
>>59074903
Except C never changed. There's no reason to think C++ is better unless the language itself shows that.

I'm very thankful the Linux kernel is still C (as it should, it has good reasons to not be C++). Couldn't keep updating it if it weren't.
>>
File: patrick-bateman-cheers.jpg (216KB, 590x322px) Image search: [Google]
patrick-bateman-cheers.jpg
216KB, 590x322px
>>59074692
>>59074717
Thanks friends, I really appreciate the help. It's easy to get lost in the abstract when I'm just in classes, it helps to know where I'm headed.
>>
>>59074903
Are there people who seriously think C++ is a viable replacement for C, and that C programmers are longing for it?
You've got to be fucking kidding.
>>
>>59074936
>150k cycles for error handling
That seems excessive.
>exceptions
Oh, carry on.
>>
NEW THREAD!!

>>59074951
>>
>>59074949
That's what schools say. It's not that surprising that they have this view.
>>
>>59074855
why?
>>
>>59074949
Most people who know C also know C++. Name one reason C programmers who work in C want to continue working in C that isn't muh performance.
>>
>>59074978
It's simpler. Really the only useful things C++ brings to the table are template metaprogramming, exceptions, and member functions.
>>
>>59074978
C++ is a clusterfuck of a language that leads to unmaintainable code and poor design decisions.
I would never pick C++ over anything.
>>
>>59074895
So what you probably have is a matrix of positions in the minesweeper table, each position representing a little square that holds a number or a mine.

The matrix has a set number of rows and a set number of columns. So you want to iterate through each position, determine what is there, then determine what character to print, and add it to a StringBuffer, which is just a dynamic string.

it'll look something like this:
public String toString() {

StringBuffer s = new StringBuffer();

for(int i = 0; i < rows; ++i) {
for(int j = 0; j < columns; ++i) {
if( position[i][j].isMined() )
s.append("*");
else
s.append("" + pos[i][j].numBorderingMines());
}
s.append("\n");
}
return s.toString();
}
>>
>>59075001
>I would never pick C++ over anything.
And yet Embedded System design is the only industry left that uses C majorly. Clearly the money and industries indicate you are wrong.
>>
>>59074937
no i don't work at all. fuck working. i only bench and write c, life is blissful
>>
>>59074978
>it's a cluttered language with very little orthogonality, it's practically impossible to write standard compliant C++, next to nobody knows enough C++ to get predictable results out of it
Hmm. Nah can't think of anything.
Not anything some random student on /dpt/ would get anyway.
Perhaps spend more time reading about a languages failings before you present it as the second coming.
>>
>>59075013
>argumentum ad populum
Good argument, fuckface.
>>
>>59075016
>2017
>Falling for the bench meme
>>
>>59075031
I am sure industries and billion dollar companies moved on because of "popularity".
>>
>>59075032
> the bench classic
>>
>>59075043
Look at the kind of languages they use, and it will only be a matter of time before you realize that it's not about languages being actually useful.
>>
>>59075043
Yes, probably.
Just look at fucking Java.
>>
>>59075070

Can we really call Java "popular" from a programmers perspective.. I don't know many who have positive views on working with it.
>>
>>59072197
I used to know how to handle this myself but have since forgotten. I learned Python because it was supposed to act the same on every platform but things like this are why I dropped it in favor of another language. Python 3 does solve this particular problem though.
http://nedbatchelder.com/text/unipain.html

Looking at an old script I wrote, I found some garbage like this
    from locale import getpreferredencoding
#printing is done in this way to replace unprintable characters, utf-8->(bytes)system encoding+filter->(string)system encoding
#if there's a better way to do this let me know
vprint("Finished: %s" % workDict["Location"].encode(getpreferredencoding(), "replace").decode(getpreferredencoding()))


I also remember having to specify utf-8 everywhere for reads and writes like this.
    rootIndex = codecs.open("index.html", 'w', encoding='utf8')


All of this stuff only applied to Windows, everywhere else it just worked on the first version without issues.

I'd advise you migrate to Python 3 especially if you're going to deploy on Windows. I personally migrated all my stuff to Go.
Thread posts: 343
Thread images: 19


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