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

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

Thread replies: 255
Thread images: 27
File: 1447182575153.gif (983 KB, 640x360) Image search: [Google]
1447182575153.gif
983 KB, 640x360
programming thread
old thread: >>51421139
>>
FUCK UMARU
>>
newfag here, what language would you guys recommend for a newbie programmer? no memes pls
>>
>>51425228
Assembly.
>>
So /dpt/, how about them allocated objects in C?
Do they have a declared type?
Do you know how to write a function to average 2 int objects?
Do you even know what C calls objects?
Are you "a shit"?
>>
>>51425196
why can't you make a proper thread?

umarufags are fucking cancer
>>
File: 1446590110179.jpg (219 KB, 1000x1502) Image search: [Google]
1446590110179.jpg
219 KB, 1000x1502
>>51425196
>this thread won't appear when someone searches for "daily"
You had one job, and you still failed miserably at it
>>
>>51425228
just learn python
>>
>>51425228
It doesn't matter, programming is about logic and solving problems over knowing language syntax.
>>
>>51425258
>people search for daily
They should be shot,desu
>>
>>51425262
how hard would it be for a beginner to get into quakec?
>>
>>51425232
kek
>>
>>51425258
>2015
>searching for "daily" "stupid" "headphones" etc.
>Literally retarded
>>
What's a good resource for preparing for a phone interview that will last under an hour that anyone here has used?

Like a book/website that gives you sample problems to solve in under 15 mins or so
>>
>>51425234
Fuck off, cancer.
You idiots ruined the last thread.
>>
>>51425228
python, simple enough and with plenty of libraries to do whatever you want.
>>
>>51425228
C++
>>
>>51425228

Anyone who recommends you anything that isn't Java, C or C++ as a first language wants you to be a NEET for life and unemployable.
>>
>>51425228
D
>>
Key=x1x2x3x4....

10thru11keys..


ANlxp+hQadO+xmTeeg0aR1YffHcioapH5vrG0+/2GcO2fQt9wB5ITUebbz6GM38SFd8kwMK3W4lfuORjVe59y0O/cKMXfqLxlijcsrpLDcNdo7nu6QM/DRHs4oJo9fKaYBVn+YyuNa+EKRo/CK0TFYMiaHQvAIVO2IFXKppW535cAESzPsyVJrdoEQS3ngYjcR0wb4PtC7PFh3w256LpDekvC3tlZJDGx5ZMi/rtA==AES

help me solve dis
>>
File: 1447745340476.jpg (42 KB, 600x448) Image search: [Google]
1447745340476.jpg
42 KB, 600x448
>>51425228
System Topology Evaluation and Reconfiguration Notation
 
~ Increment Register 1 to Infinity
A:1 <- (+) ~ Set Register 1 to Apply (+) in Series A
A:2 <- (y1) ~ Set Register 2 to State (True,1) in Series A
\\ 2,2 -> 1 ~ Connect Register 2 and 2 to 1
\\ 1,2 -> 1 # 1 $ A ~ Connect Register 1 and 2 to 1 when Register 1 Signs A
~ Brainfuck equivalent
+[+]
>>
>>51425377
Don't listen to this guy, I know both Java and C and I am a NEET.
>>
>>51425404
'ur a faget'
>>
Want to use meteor to make a fairly complex website, is it a good framework?
>>
>>51425465
This made me laugh senpaitachi.
>>
>>51425332
>I can't answer any of those questions
>I don't know C
>I got embarrassed in the previous thread
o-ok, a-anon
>>
>>51425673
I wasn't apart of your straight-jacketed retard club conversation, assume some more, kikebucket.
>>
>>51425673
>>I can't answer any of those questions
>>I don't know C
>>I got embarrassed in the previous thread
>o-ok, a-anon
>>
>>51425693
>wasn't apart
>apart
m8... you're too dumb to be anything
>>
>>51425714
And you invalidate something based on a typo.
Who else /highschool/ here? Raise your hands. Better yet, get your wranglers over here so they can drag you back. God forbid you don't eat your elmers glue.
>>
>>51425749
>I got rekt
>I'm this mad
top cuk
>>
>>51425763
All you do is assume. That's literally all you have, and the majority of the time (read: all) you're wrong and just make yourself look dumb.
My shift is over now, have fun being retarded; I'm out.
>>
File: 1399568362605.jpg (57 KB, 615x615) Image search: [Google]
1399568362605.jpg
57 KB, 615x615
>>51424819
bump
>>
>>51425784
>you rekt me over and over again with no lube
>my ass can't take it anymore
>you've made a fool of me with all your well-reasoned arguments
>now I look like a retard
>I'll take my toys and go
sounds good to me
>>
>>51425196
Why does Ruby need 20 fucking ways to do the exact same thing?
It just makes it a pain in the ass to read other people's shit.
>>
>>51425228
don't listen to >>51425377 if you want to learn those languages you can always do so later. the first language you learn has no effect on employability. just pick a language that looks nice/easy and stick with it until you can solve some basic problems or make some small software
>>
>tfw new to C
>code gets long as fuck because I'm not good with functions

I want to git gud but I feel like I don't get enough practice with them
>>
>>51426137

That's just C.
>>
>>51425973
>just pick a language that looks nice/easy and stick with it until you can solve some basic problems or make some small software

Such bad advice. My word.
>>
does dealing with strings in C ever stop being a huge pain in the ass? i'm fine with pointers in general but i prefer C++ for anything involving string manipulation.
>>
>>51426222
Do most languages let you call functions within functions? I hear you can't do that in C which kinda fucks up some ideas I had
>>
>>51426242
>I hear you can't do that in C which kinda fucks up some ideas I had

You wot, m9? Yes, you can call functions in functions.

>>51426241

Look at bstrlib.
>>
File: 1315715468561.png (120 KB, 358x321) Image search: [Google]
1315715468561.png
120 KB, 358x321
>>51426241
strings manipulation in C is a pain in the ass, end of story. I often just call a python script when I need to do it.
>>
>>51426241
I like C, but I have to agree that strings in general are just fucked up.
>>
>>51426137

If you are new to C, I recommend to read and think through the interesting arguments and the good-natured discussion in the previous thread. It'll give you just a little taste of the beautiful language C is.

Here:
>>51421139
>>
>>51426242
C can do that. However, you can't declare functions inside of functions (there is no function nesting and there are no function literals). So
int addOne(int x) {
return x + 1;
}
int main(int argc, char **argv) {
return addOne(-1); // Returns 0
}

is okay but
int main(int argc, char **argv) {
int addOne(int x) {
return x + 1;
}
return addOne(-1);
}

will not compile, since that declares a function inside of another function.
>>51426232
It's more important to understand programming concepts than it is to understand the arbitrary syntactic or semantic choices of a programming language. Once you know how to think about programming, you can generalize that knowledge to any language.
>>
>>51426298
that book title kek
>>
>>51426339

Nested functions are a Ganoo extension, actually. Not that anybody would recommend that.
>>
>>51426339
oh okay I see, I'll try that out
>>
>>51426271
>strings manipulation
>2015
Why would you ever need that?
>>
>>51426400
It really comes down to the application, sometimes your forces to do it.
>>
Strings are not objects or arrays.

Discuss.
>>
>>51426400
>strings are useless

Come on, it's 2015.
>>
>>51426470
well in C they are a array of characters...
>>
>>51426470
well in Java they are an object...
>>
Laravel or CodeIgniter?
>>
>>51425377
c#
>>
>>51425377
Golang is pretty nice, but not really used much. Ruby or PHP is nice you want a job
>>
>>51426543
C
>>
>>51426586
>PHP is nice
meme hate incoming
>>
>>51426644
i didnt say it was nice, i said it was nice you want a job. BIG difference
>>
>>51426241
It sucks and it's gonna suck until you write a macro library for doing C++-like things.
>>
Jai when?
>>
File: pinecone.jpg (1 MB, 5000x5000) Image search: [Google]
pinecone.jpg
1 MB, 5000x5000
>be truSTEM
>don't' have to deal with the retarded millennial bullshit of a meme profession like CSfags do
>>
Why is D such a heap of steaming shit?

>Create a dub project
>Keeps complaining that package.json cannot be found even though the documentation tells you to use dub.json (and so does every other project)
>Rename dub.json to package.json because fuck your errors
>No errors now until it scans for dependencies
>Now it creates a new folder for dependency, then it complains that it cannot place dependency in the folder because the folder exists
>Remove folder manually
>Same shit

Holy fucking dicks. Why is it so inconvenient?
>>
>>51426729
Use C++, C#, Rust, or wait for Jai.
>>
>>51426722
Blow will probably put it on Github within a week or two of The Witness's release.
>>51426726
Why are you on /g/?
>>
>>51426769
Excellent.
>>
File: shiggydiggyyo.png (297 KB, 640x640) Image search: [Google]
shiggydiggyyo.png
297 KB, 640x640
>>51426769
>only CSfags can post on /g/
>no other STEM members allowed
>>
>>51425228
Python, Java, or C (if you want to go bottom up). Assembly would be depressing and tedious for a beginner. I recommend you get a book for your first language (if you are going top down) it should get you get the basic concepts down quicker, then learning your next only from documentation.
>>
>>51426726
>not learning both hardware and software
shitskin engineer detected
>>
>>51425234
>Do they have a declared type?
I would assume so?
>Do you know how to write a function to average 2 int objects?
If I can assume certain things about the target architecture, yes.
>Do you even know what C calls objects?
An object in C is a "region of data storage in the execution environment, the contents of which can represent values"
>>
>>51426470
They are and they are.
>>
>>51426755
I use C++ for my daily drive. I just wanted to get back to D because despite of all the clusterfuck in the ecosystem it was a pleasant language to write in but I guess it's still a clusterfuck that's not easy to work with.
>>
>>51426846
>I would assume so?
You'd assume wrong.
>If I can assume certain things about the target architecture, yes.
It's impossible to have "int avg(int a, int b)" that works on all architectures without assumptions? How hard can it be? The average is just a number somewhere between the other 2 numbers, what corner cases are there?
>An object in C
Well done, looks like you know how to look stuff up.
>>
>>51426755
>Jai
Will never happen.
>>
File: aut.png (1 MB, 4047x538) Image search: [Google]
aut.png
1 MB, 4047x538
Who is your langfu?
No Rust.
>>
>>51426271
Why don't you use python in the first place, you fucking degenerate?
>>
>>51426787

That's right. This place is for computer scientists, not glorified electricians or mathematicians.
>>
>>51426923
>You'd assume wrong.
Elaborate please.
>It's impossible to have "int avg(int a, int b)" that works on all architectures without assumptions?
Yes, it would be very annoying though.
I'll come up with a solution.
>Well done, looks like you know how to look stuff up.
Thanks, master.
>>
>>51426938
I'm not mentally ill, thanks.
>>
>>51426935
even if he were to just drop the current compiler and post the source online I'm sure some people would revive it and develop it into a finished language, although it already seems to be usable enough
>>51426938
s-she's not in there ;~;
>>
>>51426998
Come on, it's 2015.
>>
>>51426938
you should consider going out and getting some fresh air
>>
>>51427014
>s-she's not in there ;~;
What's her name?
>>51427022
Never.
>>
>>51426972
>>
>>51426997
>Elaborate please.
It's literally in the standard. Search for "Allocated objects have no declared type", you have the document because you quoted the definition of an object from it.
>Yes, it would be very annoying though.
C might be a simple language but it's not the right language for "easy to implement without thinking too much".
>>
>>51427041
OCaml (for now)
>>
>>51425234
Yes, yes, yes, yes, yes.
>>
>>51427014
>I'm sure some people would revive it and develop it into a finished language
It's biggest problem is that it doesn't have a direction/roadmap/target/goal. No, "I want to make a language for making games" doesn't count as a goal. The guy doesn't yet know what he wants to do and makes huge swings in one direction or the other on a whim, depending on what could be "a cool feature to demo in the next podcast". I doubt it will ever reach stable. But maybe someone will pick some useful ideas from him, it does have some of those.
>>
>>51427112
Know nearly nothing about it.
>>
>>51426997
>Yes, it would be very annoying though.

doesn't seem that hard (psuedocode):

return min(a, b) + (max(a, b) - min(a, b)) / 2


am i missing edge cases?
>>
>>51427151
BLOCK CAPTURES
_BLOCK_CAPTURES_
>>
>>51427114
>meh,wrong,nope,neah,bingo
1.5/5 bretty gud
>>
>>51426938
>any language
>catching up to lisp
>>
>>51425234
No, no, no, no, no.
>>
>>51427151
I think the whole point of Jai is to have a "programming language designed by one person" with the goal of "easy to write correct code for, but easy to deliberately write wrong code for". The whole point is that it doesn't have any other big ideas or goals. Seems legit.

A roadmap should happen after/when it goes public.
>>
>>51427224
>but easy to deliberately write wrong code for
the fuck...
>>
>>51427163
>am i missing edge cases
yes, it doesn't work for the arguments 0 and INT_MIN
>>
>>51427151
This. He also has a pretty poor understanding of what he's talking about, for example blaming a data layout scheme rather than a usage pattern on poor locality properties. He also wholeheartedly believes that he's an AAA dev with lots of experience when in reality he's only made one shitty, trivial indie game and has been attempting to develop the second for what, 8 years now.
>>
>>51427092
>It's literally in the standard.
I see, what exactly does it mean though? That the underlying data behind a dynamically allocated object does not adhere to the objects type? If so, how is this not true for statically or automatically allocated objects?

Not being easy to implement without thinking too much should be the norm for any program.
>>
>>51427235
Games programming, dude.
>>
>>51427235
It's meant to be another take at C, including all its flaws.
>>
So I'm a programmer turned DBA trying to help some retarded Indians with an app that they A) did all of their "logic" in SQL using 100s of undocumented links/accounts, B) insisted on restoring production to staging instead of using a staging backup to restore staging, and C) did this during a hurried move from one datacenter to another that's already a mess without their "help."

Somebody please shoot me.
>>
>>51427237
god damn INT_MIN that always catches me out
>>
Looking for something to fill the next couple hours. What's an easy programming task I can do.
Preferably web based.
>>
int scrap = a/2 + b/2;
if(a&1 or b&1)
scrap += 1;
return scrap;

How'd I do? inb4 rounding direction
>>
>>51427352
Write a flash cards drilling program.
>>
>>51427354
Forgot the case where both a&1 and b&1.
>>
>>51427398
That is also just += 1.
>>
>>51427413
no, it would be += 0.3728847662736. Lrn2IEEE757
>>
>>51427436
u wot m8
>>
>>51427352

codeeval
>>
>>51427249
>That the underlying data behind a dynamically allocated object does not adhere to the objects type
It means that when you do "malloc(4)", there is no object type to speak of, only storage space for an object of 4 bytes. It doesn't matter to what variable you assign the return value of malloc. What matters is the type of the thing stored in those 4 bytes. And until you store something, it doesn't have a type. When you DO store something, it will gain the type of the thing you stored. Seems logical, no? The standard says the same thing (read 6.5 about expression, paragraph 6 and 7).

Most make some mistakes regardless (in the following, I'll assume sizeof (unsigned) and sizeof (float) are both 4, in order to simplify stuff and not say "sizeof blabla" everywhere):

void *p = malloc(4);
unsigned *u = malloc(4);

In the above, neither the object pointed-to by "p" nor "u" has a declared type. (Don't confuse the objects: "p" and "u" are themselves objects and they DO have a declared type; they are pointers and point to some other objects; those, the targets, have no declared type).

Now, if you do
unsigned x = 0;
memcpy(p, x, 4);
memcpy(u, x, 4);

both objects (the ones pointed-to by p and u) have an "effective type" (concept also defined in the standard) of unsigned.

If you keep the same declarations for "p" and "u" but you do the following
float f;
memcpy(p, f, 4);
memcpy(u, f, 4);

both objects will have an effective type of float. This is where almost everyone makes a mistake: they agree that the type of the object pointed-to by "p" is float, but they'll say the type of the object pointed-to by "u" is unsigned simply because "u" is declared as a pointer-to-unsigned, ie. they draw conclusions about the pointed-to object based on the type of the pointer.
That is simply not true (it's explained in 6.5 paragraph 6 in the standard) and trying to read "*u" after the "memcpy(u, f, 4);" results in undefined behavior.
>>
>>51427557
>mfw this could have been a blog post
>mfw I have no face
>>
>>51425196
sleep tight hammers
>>
>Do allocated objects have a type?
>HURR DURR I MEANT ALLOCATED MEMORY NOT OBJECTS
What is stack allocation
>>
>>51427557
>float f;
That should be initialized to something, sorry.
>>
>Implementing AVL trees
Too many rotates within rotates make JOHNY GO INSANE
>>
>>51427593
No, I didn't mean allocated memory. I meant allocated objects, it's C terminology. There's no stack allocation in C because C doesn't have a concept of stack.
And allow me to interject:
What you refer to as "stack allocation" is in fact "automatic storage" and is not what C considers "allocated".
>>
>>51427557
The section of the standard that was posted last thread only applied to a call such as float_to_u(malloc(4), ...); and not to something of the form
sometype* t = malloc(some_size);
because this causes an implicit cast, forcing the object being pointed to to have a declared type.
>>
>>51427630
>. There's no stack allocation in C because C doesn't have a concept of stack.
COMEDY GOLD!
Someone post a computer_science_graduate.jpg on top of that.
>>
>>51427630
>C doesn't have a concept of stack.
Tell that to goto
>>
>>51427607
kek
>>
>>51427636
No, the cast is made from (void *) to (sometype *); nothing is casted to (sometype). Only pointers are converted, not the contents of the pointed-to objects.
>>
>>51427673
That's with regard to the effective type, not with regard to the declared type. The declared type of the deference of a pointer is, if the pointer is not void*, the type of the base type that the pointer references; the operation is invalid on void* because then there is no declared type.
>>
>>51427652
>>51427657
fun and games until you learn C and find out that's true
>>
>>51427702
comedy gold
>>
>>51427630
>stack overflows don't exist
>>
Why does python have the best libraries?
>>
>>51427711
Oh the irony
>>
>People still discussing the C standard
This has been going on since yesterday. Is this /dpt/'s kryptonite?
>>
>>51427557
union {
unsigned u;
float f;
} var;

var.f = 10.5;
printf("%u", var.u);



Under the same assumptions, if I declare such a union and read it whether as an unsigned or a float, is it still undefined behavior to you?
>>
>>51427754
Because it doesn't
>>
Are you expected to be 100% proficient with every language you put in your resume?
>>
>>51427783
hell no
>>
>>51427707
>not with regard to the declared type
But allocated objects have no declared type. Do you agree that malloc creates an allocated object? That object doesn't have a declared type.
Oh, and malloc doesn't return to you the value of the object; it returns a pointer to the object. And you can assign that pointer to a pointer object that may or may not have a declared type.
>The declared type of the deference of a pointer is, if the pointer is not void*, the type of the base type
6.5p7 disagrees with that
>>
>>51427754
It doesn't. It has a lot of libraries but they're usually of very poor quality.
>>
>>51427783
I would say that you can't claim that you're 100% proficient in a language.
>>
>>51427800
>>51427846

I've heard horror stories where someone looks at your resume and says, "Okay reverse a binary tree in Python"...but the guy is only really good at C, and since they can't do it in Python then it means they lied on their resume.
>>
>>51427766
i think that it is considered undefined behaviour in c++, but specifically allowed in c

source: googled "union undefined behaviour"
>>
>>51427874
I think it should be fine if you can describe the operation and shit. It's the idea which count, the implementation is quite trivial.
>>
>>51427766
>is it still undefined behavior to you
No, because the standard explicitly allows it in the same 6.5p7 I was talking about: "An object shall have its stored value accessed only by an lvalue expression that has one of the following types". It lists character types and unions containing a compatible effective type as valid accesses. All the others allowed accesses are through compatible effective types.
>to you
Are you under the impression I have my own undefined behavior? We're talking about the standard's definition of undefined behavior.
>>
>>51427874
If you can't do data structure in a language you don't really know it
>>
>>51427722
it doesn't as far as C is concerned
>>
>>51427918
>>51427925

Two conflicting opinions
>>
>>51427944
Spotted the retard.
>>
>>51427952
Really? You consider you know a language if you can't make some variable assignments?
Anon...
>>
>>51427971
>it was me all along
>>
>>51427974

Knowing =/= proficient.
>>
>>51428008
What can you possibly know if you don't know how to assign a variable? That the language exists? In that case, everyone should have 300 languages on their resumes.
>>
>>51428008
>tfw you need to be proficient to assign variables
>>
File: demonhunter dpt g.png (101 KB, 357x371) Image search: [Google]
demonhunter dpt g.png
101 KB, 357x371
write a function to reverse a linked list
>>
>>51428027
>>51428040

Nevermind.
>>
>>51427924
>We're talking about the standard's definition of undefined behavior.
Then, if it's the standard's definition, why does the construct we discuss for two threads now is still allowed by compilers? As for encoding of floats, type assumption of dereferenced pointers is implementation-dependent. And in GCC case, this type is assumed to be the same as the declared type of the pointer.

Well, I learned something, that's for sure, but it doesn't absolutely change how programs are compilated and run in the general case.
>>
>>51428044
but what if the list has a loop
>>
>>51427713
also never used code tags
>>
>>51427783
think for yourself... wouldn't you get pissed off as an employer if some cunt said they knew some language but it turns out they're full of shit? there's no way you'd give them the job
>>
File: 1433412794170.jpg (25 KB, 500x412) Image search: [Google]
1433412794170.jpg
25 KB, 500x412
Hello fuccbois. I know visual basic and I'm moving on to python. What ide should I use?
>>
>>51428105

I know English and French. I can understand when someone speaks French but I can't talk French back to them, doesn't mean I can give a speech in French or write a story in French but it also doesn't mean I don't know French. I'm very comfortable communicating in English, so am I full of shit if I say I know French?
>>
>>51425228
68k ASM
so you can make sonic romhacks
>>
>>51428129
Komodo.
>>
>>51426241
tell me about it
try reading an utf-8 file and manipulating it
such a headache
>>
>>51428027

Look, we run a brainfuck shop here. If you can't assign a variable in brainfuck, you're out.
>>
>>51428209
Wait. Do you have to normally pay for ide's?
>>
>>51428218
+
Do I win?
>>
>>51428224
*Komodo edit.
>>
>>51428166
Yes. Understanding != knowing.
>>
>>51428243

That's not a variable, son. You're fired.
>>
>>51428269
Sorry, I know variables, not pointers.
>>
>>51428166
then you don't really know french imo. i wouldn't claim to know german even though i can more or less understand what people say when they speak german
>>
Why is working in Go so nice, everyone keeps saying it's shit, and for all I know, it is, but it's a joy to work with.
>>
>>51428044
for(int i = 0; i < list.size(); ++i) {
System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDo your own homework, faggot");
}
>>
>>51428288
Come back when programming means more than fizzbuzz to you.
>>
>>51428262
>>51428283

So let's say you can "assign a variable" in language 2. What if someone asks you to go beyond that, and you can't do it, where does the line end between knowing and not knowing?
>>
>>51428306
you should be able to write at least a decent program in that language. you don't have to know as much as stroustrup about C++ to put it on your resume but you should be able to write a functioning program with hardly any difficulty.
>>
>>51428306
If you can do arbitrary operations idiomatically in a language, then you know the language.
>>
File: wakemeup.png (141 KB, 1912x705) Image search: [Google]
wakemeup.png
141 KB, 1912x705
>
>>
>>51428278

You still can't have the job.
>>
>>51428306
Implementing normal data structures.
>>
File: mfw.png (107 KB, 323x241) Image search: [Google]
mfw.png
107 KB, 323x241
>>51428294
>not being able to reverse a linked list
>>
>>51427874
>reverse a binary tree in python
This a feminist twitter meme. Regardless, and giving you a proper answer: It depends on what you're asked to do. Implementing your own linked list would be expected/an okay question. Asking you to implement red/black trees would be overkill. It also depends on the language itself (it's much more painful to implement data structures in C than in something like Java).

There's no single answer to your question.
>>
>>51428327

>a decent program

This is a subjective term.
>>
>>51428298
Ouch, you sure got me bro
>>
>>51428384
Live and learn.
>>
>>51428072
>still allowed by compilers
Because compilers can't solve the halting problem. They can't proactively detect cases of undefined behavior and even if they do they are not required to warn about it. They trust that you won't cause undefined behavior and their optimizers are tailored to that.

All it boils down to is that you must read an object using the effective type suitable for the value stored in that object. The compiler won't go out of his way to forbid you from reading an unsigned through some float pointer aliasing (eg. float f = 1.0; unsigned u = *(unsigned *) &f;) but the standard says it's undefined behavior and what you get has no guarantees with regard to portability on other conforming implementations. (as a side note, float f = 1.0; unsigned u; memcpy(&u, &f, sizeof u); is well defined because the value is required to be "blessed" -- for the lack of a better term, I'm borrowing this one from perl -- by the standard; whether what you obtain in u is what you expected or not is implementation defined however, including stuff related to padding bits and whether accessing the value afterwards raises a trap or not).

There's a lot of shit you can get away with, for example all object pointers have the same size on mainstream implementations so you can sneak in stuff like:
void null_this_ptr(void **x)
{
*x = NULL;
}
void test(void)
{
int *x;
null_this_ptr((void **) &x);
}

but this is still undefined behavior because sizeof (void *) is not guaranteed to be equal to sizeof (int *); what is happening (in null_this_ptr) is that you're writing the object *x through an expression that has an effective type of "void *" while the underlying object has the effective type "int *". This is exactly the same kind of violation that 6.5p7 forbids.
It's more obvious here, because you can easily point out the flaw by referencing the sizeof (void*) != sizeof (int*) relation. It's less obvious in the original case with allocated objects.
>>
>>51428369
if you can't even do fucking fizzbuzz or any other bottom tier interview exercise you're a retarded fucking spic for thinking you know that language. if you're able to do those you should be able to work on any other program if you're a decent human being that dares to call himself a programmer. being able to assign a variable? that's fucking nothing FUCKING RETARD
>>
>>51428427
It is 100% well-defined. Since you don't know a single thing about C, fuck off.
>>
>>51428448

>Hurr fizzbuzz

This is the kind of stupidity I'm talking about.
>>
>>51428450
>I've been fizzbuzzing since 2007
>>
File: sophisticated_feels.jpg (152 KB, 407x625) Image search: [Google]
sophisticated_feels.jpg
152 KB, 407x625
>>51428448
>being this assmad
>>
>>51428461
retard
>>51428492
>le simpsons meme
spic detected
>>
>>51428507

Back to your "which phone should I buy?" general dumbass. Adults are talking.
>>
>>51428523
nice projecting stupid kid
>>
It should be a bannable offense to talk about C in these threads.

Not because I hate C, but because people cannot stop arguing about it.
>>
In Notepad++ how do I quickly change a single Character of a ton of variables? Clearly the character I want to change is unique in each of them to the variables
>>
spics are possibly even worse at programming than the plebbiest of curryniggers
>>
>>51428536
>projection meme
time for a homescreen thread!
>>
>>51428566
POO

IN

LOO
>>
>>51428557

Did one of them become your step-dad? You sound awfully bitter.
>>
Is there a full version of the guitar jingle in the SICP lectures?
>>
>>51428591
i gave you solid advice and it's on you if you don't want to listen. don't put a programming language on your resume if all you know is how to assign a variable. but that's your culture in india, where lies and deception is completely normal, and we must accept our cultural differences because equality is such a great thing :^)
>>
>>51428546
>people cannot stop arguing about it
>argue
>synonyms: discuss, debate
not good? how about a headphones general? generic animu maybe? are you in the right thread? intel vs amd? finished and bankrupt?
really, what's your level? what kind of posts would you be comfortable with?
stupid tripfag
>>
>>51428627
tell me how the code in the previous OP had undefined behavior tard
>>
>>51428641
wha'?
>>
C strings are such a pain in the ass.
Why does this segfault every time?
I even made sure that len isn't zero.
I literally cannot write to this char array.
char *arr = (char *) malloc(sizeof(char) * len);
*(arr+0) = 'A'; /* test write */
>>
>>51428649
someone was saying >>51421139 had undefined behavior
>>
>>51428627
>stupid tripfag

I've been posting in dpt longer than you have, scrublord.

undefine yourself.
>>
>>51428651
you don't have to cast the return value of malloc
you don't have to write sizeof (char), it's always 1
what's len and what's its value?
>>
>>51428623

Thanks for your opinion Jebadiah
>>
>>51428660
>someone
and why do you ask me?
>>
>>51428671
well len in this case is 4 right now.
>>
>>51428651
>I even made sure that len isn't zero.
Could it be negative, or stupendously huge (more than, say, a hundred million)? That may cause the allocation to fail.

Note that in general, you need to check malloc() calls for returning NULL. Always, without exception.

Assuming you checked that it does *not* return NULL, that code should be perfectly fine and should NOT segfault. Are you sure this particular piece of code is to blame? It really shouldn't be.
>>
File: stallman_game.gif (1023 KB, 798x599) Image search: [Google]
stallman_game.gif
1023 KB, 798x599
>>51425196
I'm making a VN. You're Lain Iwakura, a Japanese transfer student to MIT! You meet some really interesting people, form some important bonds and most importantly, create some life-long relationships. <3
>>
>>51428602
I don't think it's a guitar, just some kind of electronic piano, but the song is Bach's Jesu, Joy of Man's Desiring, and I'm sure you can find a guitar version to your liking if you search.

https://www.youtube.com/watch?v=NBrCa6GXzrU
>>
>>51428668
how about desktop threads? watch threads? /sqt/? c'mon brainless tripfag, don't hold out on us now! is this more like your level >>51428602 of posts? or >>51428581 ? you understand those?
>>
>>51426470
This. They are linked lists.
>>
>>51428694
I checked, it's not returning null.
I just can't write to it.
if ((arr = (char *) malloc(sizeof(char) * len)) == NULL)
{
printf("arr points to null\n");
}
*(arr+0) = 'A'; /* test write */
>>
>>51428732

u r 2 mad m8
>>
>>51428788
>I just can't write to it
you have undefined behavior in the parts of code that you're not showing
>>
>>51426995
>computer """""""""""scientists""""""""""""
>not glorified codemonkeys and autismo neets
oop in loo
>>
>>51428660
It's been already explained, evaluating *u has undefined behavior under the standard because u gets the float * effective type after memcpy whereas the declared type of *u is unsigned. The standard doesn't tell whether you should assume that *u is a float or an unsigned. That's what is this fuss is about. Implementation breaks this indecision.
>>
>>51425196

I'm making a binary search tree for class, and whenever I move down the left or right pointer of my parent, the pointer moves to the spot I am at and doesn't move back up to the parent...
As an example, say I insert a 10, then a 5, then a 3. They all move down the left side of the tree as expected. Then say I add a 4... instead of being attached to the 5's right child, it is attached to the 3's right child instead...

Any ideas, comments, trolls?


void BST::insertHelper(Node*& nPtr, int item) // insert an item into BTS, do not allow duplicate numbers
{
if (root == nullptr) // if nothing in tree - insert node
{
cout << "Made a new node";
root = new Node<T>(item);
}
// if something in tree - check to see if less or greater than node you are on
else if (item < nPtr->data)
{
if (nPtr->lchild != nullptr) // if left child has a value, traverse left once
{
insertHelper(nPtr->lchild, item);
}
else
{
cout << "Made a left node, attached to " << nPtr->data << endl;
nPtr->lchild = new Node<T>(item);
}
}
else if (item > nPtr->data)
{
if (nPtr->rchild != nullptr) // if right child already exsists, traverse right once
{
insertHelper(nPtr->rchild, item);
}
else
{
cout << "Made a right node, attached to " << nPtr->data << endl;
nPtr->rchild = new Node<T>(item);
}
}
else // parent has no place for item to go
{
cout << "The input " << item << " has already been added to the tree." << endl;
}
}
>>
>>51426787
>>51426726

>EEfag troll got accepted to some engineering degree
>>>/sci/
>>>/diy/
>>>/trash/
>>
>>51428812

You know, I've been waiting for someone to respond to that shitpost. I'm glad you finally did. Thank you.
>>
>>51428696
I laughed. Keep on going.
>>
>>51428809
I do not.
I haven't even touched *arr anywhere else in the code.

i turned on -Wall and now i'm getting this
warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
printf("arr contains %s\n", *arr);
>>
>>51428800
so this is your level.
here goes:
botnet
ebin
meme
it's happening
why is this allowed
c᠎uck
this s᠎mh t᠎bh f᠎am
>>
>>51428853
You know what, you've motivated me to push through!
>>
>>51428824
I got it wrong, it's not evaluating *u, but evaluating *p that undefined in >>51421139.
>>
>web developers think they are programing
>they will never know what they are missing....

I hear this quite frequently. do you agree, /dpt/?
>>
>>51428044
(define (reverse lst)
(if (null? lst)
'()
(add-to-end (car lst) (reverse (cdr lst)))))
(define (add-to-end item lst)
(if (null? lst)
(list item)
(reverse (cons item (reverse lst)))))

;^}
>>
>>51428870

Mention a few things about Object Oriented Programming and I'm good.

After all, it's the one true paradigm.
>>
File: lol why u mad tho.jpg (68 KB, 640x550) Image search: [Google]
lol why u mad tho.jpg
68 KB, 640x550
>>51428870
>>
>>51428896
big dick playa!
>>
>>51428886

Why don't you go ask them?

>>>/g/wdg
>>
>>51428044
in haskell:
reverse
>>
>>51428886
web dev is for fegs
>>
>>51428840
void insert(int x, Tree& T)
{
if(T == NULL)
{
T = new Node(x, NULL, NULL);
}
else if(x < T->item)
{
insert(x, T->left);
}
else if(x > T->item)
{
insert(x, T->right);
}
}
>>
>>51428546
>waah people are discussing! ban them!!!
>>>/pol/
>>
>>51428699
I'd guessed that it was something by Bach. Thanks.
>>
i++ or ++i which one is better
>>
Does anyone know a good site to learn math starting from the basics?
>>
>>51428945

People should only talk about OOP languages in this thread.
>>
>>51428981
i++ if you intend on evaluating i before incrementing it. ++i if you intend on incrementing i before evaluating it.

!^)
>>
>>51428981
Neither, they do different things
>>
>>51428993
>>>/trash/
>>
>>51428869
>I haven't even touched *arr anywhere else in the code.
Yes you have -- you touch it in that printf call. And *that*'s where it segfaults.
>>
File: serveimage-3.jpg (2 KB, 48x48) Image search: [Google]
serveimage-3.jpg
2 KB, 48x48
>>51428993
What if I don't? What're you gonna do about it, faggot?
>>
>>51428981
they're completely different
>>
>>51428869
Should be:
    printf("arr contains %s\n", arr);

But agree with everyone else, you're obviously doing something fucked up elsewhere in your program, and just not showing it to us because you're embarrassed. And rightly so.

#include <stdio.h>

int main (int argc, char ** argv)
{
int len = 10;
char* arr = (char*) malloc (sizeof(char) * len);
*(arr+0) = 'A';
*(arr+1) = '\0';
printf("arr contains %s\n", arr);
}


C:\>test.exe
arr contains A
>>
>>51429039

Then you are part of the jewish conspiracy.
>>
>>51428840
How do you call this function? And why does it have this strange pointer to reference thing?
>>
>>51428840
>As an example, say I insert a 10, then a 5, then a 3. They all move down the left side of the tree as expected. Then say I add a 4... instead of being attached to the 5's right child, it is attached to the 3's right child instead...

Not following you... shouldn't the tree look like this after inserting the 4:

    10
/
5
/
3
\
4


Sounds like it's doing the right thing. It would be wrong for 4 to be the right child of 5. But 6 would be a different story.
>>
>>51428840
What you are talkign about is called a self-balancing tree. However what this anon said is right
>>51429190
I'm guessing what you want it to do is something like this. Sorry ahead of time if the format is super fucked.
        10
/
4
/ \
3 5
>>
Best ide for python?
Thread replies: 255
Thread images: 27

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

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