[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: 313
Thread images: 34

File: lambda cube.png (6KB, 321x294px) Image search: [Google]
lambda cube.png
6KB, 321x294px
Lambda Cube Edition

What are you working on, /g/?
Which vertex are you at?
>>
Algebraic effects are useless
>>
thank you for not using an anime image
>>
>>56076273
Who /postscript/? Computerphile reminded me of how comfy it could be.
>>
File: pouting.jpg (12KB, 500x281px) Image search: [Google]
pouting.jpg
12KB, 500x281px
>>56076298
rude
>>
File: 1467398868589.jpg (475KB, 852x973px) Image search: [Google]
1467398868589.jpg
475KB, 852x973px
Are we being raided by lainchan?
Is such a thing even possible?
When did they develop this capability?
>>
File: what is wrong with C++.png (181KB, 745x792px) Image search: [Google]
what is wrong with C++.png
181KB, 745x792px
this is one of the C++ gurus
>>
>>56076273
>not the lambda tesseract
Get on my level
>>
>>56076345
>>56076322
thank you for practicing sexual abstinence
>>
>>56076384
Effects? They're basically just types
>>
>>56076391
I guess you know all about its benefits.
>>
File: 1357762837271.jpg (31KB, 300x286px) Image search: [Google]
1357762837271.jpg
31KB, 300x286px
>>56076345
>not succumbing to the sheer power of the lain

>>56076391
Thank you practising homosexual promiscuity.
>>
>>56076411
I am beyond types
>>
>>56076417
I knew it

There's no way we'd so suddenly get so many people knowing what they're talking about
>>
>be programmer
>feel dumb; all those scientists, engineers, and mathematicians make fun of me
>browse /g/
>hey what's this...
>ALGEBRAIC LAMBDA FUNCTOR APPLICATIVE MONAD
>oMG it's math but it's programming??!!!!!!1
>now i can feel smart too...
>>
Is the Tup guy here? I have a question. Does it support autotools-like functionality?
>>
File: sour grapes 2.jpg (14KB, 300x250px) Image search: [Google]
sour grapes 2.jpg
14KB, 300x250px
>>56076464
nice projection
>>
File: 1466120522034.png (287KB, 599x450px) Image search: [Google]
1466120522034.png
287KB, 599x450px
>>56076464
this, you should just use oop like all smartist people
>>
>>56076501
>that mongodb icon
Fucking kek
>>
>>56076464
>implying programming isn't applied math anyway
>>
>>56076446
>Is someone not a programmer because they're not interested in PHP?
Dumb argument. You and I know roughly what PHP is good at, and when we'll be faced with a problem it could solve, we'd reluctantly jump to using it. (never gonna happen but that's not the point) You admit you have absolutely no idea what Tup is good at, so you should chiggidout so you know what the author (not me btw) was thinking when he made it.

>I might have even looked at this thing if you hadn't shilled it so hard.
Oh poor you! Did I trigger you? Do you need a safe-space rn? Is it hard leading your life basing your opinions according to how people defending one PoV or the other made you feefeel deep down?
>>
File: 238740.jpg (304KB, 1191x1215px) Image search: [Google]
238740.jpg
304KB, 1191x1215px
>>56076554
>>
>>56076554
Hey, I had a question, see >>56076470
>>
>>56076524
programming is puzzle solving >>56076369
>>
File: Bunny-hug.jpg (158KB, 500x667px) Image search: [Google]
Bunny-hug.jpg
158KB, 500x667px
>>56076322
>>
http://incredible.pm/

fun with curry-howard
>>
File: 1470933914110.jpg (14KB, 310x464px) Image search: [Google]
1470933914110.jpg
14KB, 310x464px
I need to write a program to track multiple moving objects on a camera in real time and then save and analyze their paths. I'm pretty lost on the first part, as I never worked on any video analysis not even static image analysis. Can you recommend some good literature or helpful links?

I only found "image sequence analysis" by Tsai and Huong which is pretty old so I'm not quite sure if that's good to use. Otherwise all I found were books on static image analysis.
>>
http://github.com/deeepaaa/rana
>>
>>56076470
define "autotools-like functionality"
>>
>>56076711
I mean, can it handle setting up the correct compiler, fixing up differences in header files, doing cross-compilation, that sort of stuff.
>>
I'm trying to run PDCurses on windows but I don't even know where to start. I can only do basic as fuck compilation (gcc main.c -o main.exe kinda thing), I don't know if I can just import the curses.h right away or if it needs to be build still.

pls help
>>
Algebraic effects are for more than just reasoning about effects, they're for implementing them. It's free monad + interpreter in a sexy package.
>>
File: sxml.png (93KB, 692x492px) Image search: [Google]
sxml.png
93KB, 692x492px
>>56076697
>not using sxml
shig.jpg
>>
>>56076736
No. That's not it's goal. You'd have to adapt the output of another tool to it, which is not undoable (it can include a config.tup file with CFLAGS=whatever), but it's not included. Note that make proper doesn't either, and that cmake does not include a make.
>>
Why doesn't my fizzbuzz work when checking for matches?

function FizzBuzz(length, bool, map){
this.length = ++length;
this.bool = bool;
this.map = map;
};
FizzBuzz.prototype.fizzbuzz = function(){
console.log(
Array.apply(
null, new Array(this.length)).map(
Number.call, Number).map(
i => {
let c = ''
this.map.forEach(
(
a,
b
) => (
this.bool
)?(
!(
i%b||(
''+i
).indexOf(
b
) != -1
)&&(
c += a
)
):(
!(
i%b
)&&(
c += a
)
)
)
return (c)?c:i
}
).slice(
1
).join(
'\n'
)
)
}
var FizzBuzzer = new FizzBuzz(100, false, new Map([[3, 'Fizz'], [5, 'Buzz'], [7, 'Woof']]));
FizzBuzzer.fizzbuzz();
>>
>>56076680
Are the moving objects the only things that are moving? What language are you using?
>>
>>56076862
Lang? looks like JS.

What do you mean by 'doesn't work'?
>>
File: krispy seen some shit.png (283KB, 692x421px) Image search: [Google]
krispy seen some shit.png
283KB, 692x421px
>>56076862
>jshit
>pseudo-functional bloat
Of course it won't work, dumb shit. Consider sudoku.
>>
File: Stormweenie.jpg (67KB, 476x717px) Image search: [Google]
Stormweenie.jpg
67KB, 476x717px
>>56076930
>>pol
>>
>>56076887
Well since it's real time I thought C would be best for performance. Yes they should be the only thing moving.
>>
File: le typical stormfag.jpg (670KB, 1706x2064px) Image search: [Google]
le typical stormfag.jpg
670KB, 1706x2064px
>>56076930
Shoo poltard.
>>
>>56076898
it outputs wrong things
but i got this now
>>56076930
thanks asshole
>>
In 2016 AD is it safe to assume GLint or EGLint will always be 32 bits?
>>
>>56076978
Are the objects of some particular shape and/or color?
>>
File: le stormfag monkey.png (247KB, 999x1200px) Image search: [Google]
le stormfag monkey.png
247KB, 999x1200px
>>56076930
Go back to /pol retard
>>
>>56077097
No
>>
>>56076973
>>56076989
>>56077180
samefag
>>
>>56076680

Try OpenCV,(Open Computer Vision) you can use C,C++, Python and maybe even Javascript to use that library. Check the books in google, there are a few.
>>
>>56077216
this
>>
Two days into assembly and I don't wanna do this, what a piece of shit lel, I understand it but it's such a mess
>>
what does CRUD mean?
>>
>>56077261
>how do i google
>>
>>56077229

>it's such a mess
if you learn it, you would be better programmer. I'm still stuck in C/C++ and doing every shit to get improve my skills. Keep learning assembly mate and learn computer architecture too, you would be proud/
>>
>>56077264
sometimes some acronyms stand for other things and its hard to find their tech meaning retard
>>
>>56077279
>Crud or CRUD may refer to:

>Waste, dirt, feces, or something of poor quality
>Create, read, update and delete (CRUD), basic functions of a computer database
>>
>>56077278
I heard that alot from the idiots here and it looks like they don't know what they are talking about, I read alot of assembly before and two days of writing it I am disgusted, its just a huge hassle and would rather let the compiler do it. Stick to C and C++ my man, learn to read but dont write yourself except for SSE3 etc, its a mess
>>
>>56077295
what if the guy reads a manual that says "do a crud on your computer" and takes a shit on the laptop??? huh??? bet you didn't think of that
>>
Does openCV work with python3? if it does. can someone tell me how to get it on ubuntu
>>
>>56077311
what about it?
>>
>>56077304
and its still worthwhile skill mate. If you're looking for a job assembly is a pain in the ass, but if you're willing to be a good programmer assembly is huge advancement. Its still used in industry. Assembly isn't that hard if you already know other language or algorithms.
>>
>>56077320
kek
nothing sanjeep, you got me
>>
>>56077319
Google is your friend
http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/
>>
>>56077334
the language itself is pretty simple (instructions, addressing modes, flags, very simple) but to do anything worthwhile in it just takes way too much work, and it's so hard to debug (gdb snippets of C code isn't so hard) I'll just write hardware init code in it and jump to C i guess
>>
>>56077342
I literally have no clue why I couldn't find this yesterday, thanks
>>
>>56077341
ok, rajesh
>>
>>56076273
Loving C so far.

The speed is amazing compared to Python routines.

Any draw back to include gards, conditional includes and macro defines?
>>
How exactly does sizeof() work in C++? I used it on a class I made and it returned 112. Then I used it on an instance of that class, and it returned 4.
>>
>>56077684
>on an instance of that class, and it returned 4.
Surely 'twas a reference. Poast code.
>>
>>56077684
I know nothing about C++ but sizeof probably ruturned the number of bytes an instance of the class occupies the first time while it only returned the size of the pointer to the instance the second time (assuming you're on a 32-bits computer)
>>
>>56077721
Yes, when it returned 4 I had used it on a pointer. I guess that makes sense.
>>
>>56077750
Yop. Also I'm full of shit:
>When applied to a reference type, the result is the size of the referenced type.
But yeah, pointers aren't references, and they occupy a fixed size
>>
>>56077777
OMG I COMBO'D x5!!!

sauce: http://en.cppreference.com/w/cpp/language/sizeof
>>
>>56076862
What the ever loving fuck is this.
>>
for anyone wanting a practical use of Haskell
GHCI is good for doing command line stuff, assuming you're using some (normally standard) packages like directory, unix, windows, etc.

you can escape command line stuff from the interpreter with :!

basically like command line++
>>
>>56077835
Welcome to JavaScript!
>>
>>56077684
>Then I used it on an instance of that class, and it returned 4.
No, you used it on a pointer to your class instance.
Also, you're on a 32bit machine.
>>
>>56077879
NO SHIT SHERLOCK! It's been 10 minutes since we figured it
>>
File: computer.png (5KB, 572x86px) Image search: [Google]
computer.png
5KB, 572x86px
>>56077879
oi m8 the fck u just say i'll hook u in th gabber m8 i swear on me mum
>>
Is Rust still considered a meme?
Multiple SO surveys show that it's the coolest thing that currently exists, but I still hear that it's absolute shit.
>>
>>56077988
You can really tell it's trying to replace C++ given it's god awful fucking syntax
>>
>>56078017

I submit that Rust is WORSE than C++ in terms of syntax.
>>
>>56077988
It's a good meme m8.
>>
>>56078039
i () -> = { := case { agree } frob -)
>>
File: index.png (5KB, 238x212px) Image search: [Google]
index.png
5KB, 238x212px
>mfw using visual studio without visual assist
cheap motherfucker doesn't want to pay 90 bucks
>>
>>56078222
dumb r9k neet 90 bucks is not free
just live without the shitty refactoring
>>
File: idiot sandwich.jpg (58KB, 552x621px) Image search: [Google]
idiot sandwich.jpg
58KB, 552x621px
>>56078222
>using visual studio
>>
>>56078242
It's a good IDE
>>
>>56078242
It's the best of the worst.
>>
/pol/ is even stupider than /biz/ and /g/ combined
>>
>>56078439
what does that have to do with anything.
>>
>>56078242
>LOL USING MICROSOFT PRODUCT :DDDD

It's like you don't even try to educate yourself at all on any of the shit you spout.

Visual Studio is a fantastic IDE, get your head out of your arse.
>>
>>56078460
Wow, learn to take a compliment, fag.
>>
>>56078468
go shower
>>
>>56078468
>protecting microsoft
>even though i didn't even mention it
Something doesn't add up here.
>>
File: FtMy3v1.jpg (77KB, 394x700px) Image search: [Google]
FtMy3v1.jpg
77KB, 394x700px
Hello /dpt/, not a regular poster seeking help. Which language would be the best tool for automating interactions with web pages?

Say there is a form on technology.bike and I'd like to input something into it based on logic and submit it.

Or say you wanted to make a bot to mass vote on a poll

I hope I explained the use case well enough, I have little experience.
>>
File: images.jpg (2KB, 125x160px) Image search: [Google]
images.jpg
2KB, 125x160px
No maki picture, shame on you op
>>
>>56078497
There's literally nothing wrong with Windows 10
>>
Do employers still use fizzbuzz to weed out candidates? I'm geniunely curious now that everyone and their mother can google "fizzbuzz" and get examples of it.
>>
>>56078509
python lib "mechanize" is pretty good if you want something very high-level.
>>
>>56078509
autohotkey or python should work and be easy enough to learn
>>
>>56078532
You have to understand that the fizzbuzz test is a literal retard filter.
Many people put on their resume that they're programmers without having ever touched code and think they can get away with it.
They're not inquisitive enough to actually look up how to feign programming knowledge, they're too stupid for that.
They're just looking for an easy break into another industry.
>>
>>56078540
I tried a macro but I'd like it to just run in a terminal, I don't want to see the web page freaking out.
>>56078535
I'm looking into this, thank you.
>>
Can I write an IRC client in Rust and expect it to work just as well on Windows as it would on Linux?
>>
>>56078749
No, you shouldn't expect anything to work well on Windows.
>>
>>56078749
Why would you write an IRC client?
>>
>>56078749
(((Rust)))
>>
>>56077946
>falling for the 16 GiB RAM meme
>>
>>56078788
in 2016 it's like the bare minimum for a new pc
>>
#include <stdio.h>

main()
{
int p, d;
_Bool isPrime;

for (p = 2; p <= 20; ++p){
isPrime = 1;

for ( d = 2; d < p; ++d){
if (p % d == 0)
isPrime = 0;
}

if (isPrime != 0)
printf("%i ", p);
}

printf("\n");

return 0;
}


why the second for loop works?
if p=2 and d=2, and the condition is d<p, why does this work?
>>
>>56078773
You're a funny guy.

>>56078777
I guess it's more of a IRC bot and client kind of deal, not just a client.
>>
>>56078825
It probably doesn't run on the first iteration of the outer loop. Post the output of the program.
>>
>>56078825
first iteration does nothing
second iteration - ++p so p is 3
d is now < p
etc
>>
>>56078872
I'm asking why you would want to write one when there's so much existing stuff in place you could use (google it)
>>
is there like a website that gives coding challenges that start simple but get more complicated as you progress? I haven't been programming in a while and I want to start again but i don't know what to make
>>
>>56078825
great opportunity to learn how to use a debugger
>>
>>56078439
/pol/ is retarded because almost no one goes there except for retard nazis

/biz/ is still new and small
>>
>>56078899
I want a portable SSH-like program over IRC. Bots will run on my PCs and I will send them simple commands (lock the screen, run some script, send file, etc.).
I have a somewhat working Python version, but I want to rewrite it in Rust just to see if I can.
>>
>>56078825
The second loop never executes when p=2.
>>
>>56078968
Gee I wonder who could be behind this post
>>
Hi, I'm a complete shitter trying to start messing around in pythong, but I only know the interactive interpreter.

What should I use to start making very little simple things on linux with python?
>>
>>56079014
google shebang
>>
>>56078825
You can make that go alot quicker by checking whether d*d<=p
>>
literally how do i dynamically create an array with a for loop and malloc in C
>>
>>56079057
>with a for loop

no
>>
>>56079057
What exactly are you trying to accomplish?
>>
>>56079057
linked list nigga
>>
>>56076273
I'm thinking of making a wget script that downloads the desired page then deletes it then wgets it again just to take bandwidth is this the most efficient way?
>>
>>56079057
Don't dynamically create an array with a for loop. First off even if you take care that memory is being freed properly it's still incredibly slow to malloc every iteration of the loop.
>>
>>56079037
I tried googling but I should be doing wrong searches because I can't understand anything.
>>
>>56079057
>mfw people still use malloc when calloc exists
>>
>>56079064
>>56079089
okay, but this would require looping twice i think, once to figure out how much memory to allocate, allocate it, then loop again to populate it
>>
>>56079014
The interactive interpreter is the Python programming language. Just do what you'd normally do with the interpreter but save it to a text file instead.
>>
>>56079112
>zero initialising
>ever
>>
>>56079112
>wasting time zero initializing
>>
>>56079112
No reason to use calloc other than the overflow protection.
>>
>>56079112
>not preaching reallocarray
>>
>>56079112
calloc more cpu intensive.
>>
>>56078825
output is
2  3  5  7  11  13  17  19


this is an example from kochan "C Programming", chapter 6, program 6.10
>>
>>56079129
Like, trying to openning it with the itnerpreter? I tried to open something like example.py with the interpreter and couldn't do it. I feel very retarded.
>>
>>56079129
>The interactive interpreter is the Python programming language
The Python programming language is a programming language, not a program.

>>56079165
$ python name.py
>>
>>56079165
Are you in POSIX or Windows.

On POSIX provided your path is set correctly you should be able to just type:

python /path/to/script

On Windows you can also set a path to python but if you don't have one set the python executable is usually found in C:/Python27/pythonw.exe
>>
>>56079128
rarely do you want to allocate memory every iteration
>>
>>56079194
>The Python programming language is a programming language, not a program.

Stop splitting hairs you know damn well what I meant.
>>
>>56079229
It was very clear what you mean. You meant what you wrote.
>>
>>56079230
Spotted one
>>
>>56076318
I've been trying to get into it, but I can't find a good place to start.
Any good resources I should check out?
>>
>>56079256
99% of the time CPython is the implementation people refer to when they use term Python programming language. Stop being a contrarian cunt.
>>
>>56079194
I do that but just executes the file, it is what it should do?

>>56079212
I'm on Void, so I guess is POSIX
>>
>>56079289
No, when people use the term "Python programming language" they mean the Python programming language, not any implementation.
Also, CPython is objectively one of the worst implementations, sane people use either Cython or Pypy.
>>
>>56079291
>I do that but just executes the file, it is what it should do?

Make sure your script is actually outputting anything to the stdout (usually the console).
>>
>>56079291
>I do that but just executes the file, it is what it should do?
I guess so, what did you expect it to do?
>>
>>56079317
I filled it with random characters to ensure it wasn't failing to open insteaf of showing nothing (what file had)

Should I put inside some random line, like print "Hello World!" for testing?

>>56079332
Open to edit it, like I use some word editor.
>>
>>56078968
not just nazis like there was a couple of canadian communists that thought wealth was a zero-sum game
>>
>>56079291
>>56079317
>>56079332
I think I see his problem. In the interactive Python shell almost every operation outputs a result.

With Python the programming language you have to tell it to print.
>>
>>56079343
>Open to edit it, like I use some word editor.
But implementations of programming languages are meant to either compile the program or execute it, not edit it. You would use an editor for that.
>>
>>56079371
I see, I'm starting to understand it.

There's some remarkable Python editor I should check?
>>
>>56079388
Emacs
>>
Why the FUCK should a programmer have to do analyst work.
Fuck this assignment.
>>
Someone redpill me on relational programming pls.

>>56078909
Project Euler?
>>
>>56079411
>relational programming
Sounds like some kind of meme term.
>>
>>56079406
Post the assignment.
>>
>>56079388
all python editors are shit and everything that has to do with python is shit
>>
>>56079429
No.

I have to produce a feasibility report for a new accounting system for some shit phone company.
How has this got anything to do with programming. This pisses me the fuck off.
I'm not a fucking analyst, I have no idea what to do.
>>
>>56079461
Wow that sucks ass.
>>
>>56079406
>why should a code monkey have to think for himself
ok pajeet
>>
File: what_is_this_slut_saying.png (132KB, 835x296px) Image search: [Google]
what_is_this_slut_saying.png
132KB, 835x296px
>>56076273
>root searching code using Runge-Kutta 4
>it returns different results every time it's run
What the fuck
>>
>>56079506
this is why you write pure functions :^)
>>
>>56079506

Side effects were a mistake.
>>
>>56079079
>i just passed CS 1 look mom
>>
File: 2000px-Haskell-Logo.svg.png (36KB, 2000x1412px) Image search: [Google]
2000px-Haskell-Logo.svg.png
36KB, 2000x1412px
>>56079506
You only had to listen
>>
File: 1321900613960.jpg (46KB, 294x356px) Image search: [Google]
1321900613960.jpg
46KB, 294x356px
>>56079079
>linked list
>>
>>56079584
>tfw this issue can occur in Haskell too
And I thought you were pure ;_;
>>
>>56079629
wow you have to have really fucked up to have made that mistake in haskell
>>
>>56079629
When does that happen out of curiosity?
>>
>>56079128
allocate a sensible amount at first, and then if you need more you realloc it
>>
>>56079079
>malloc is cpu taxing
>i'll just malloc every time I need to add a new piece of data
>>
>>56079653
When you use side effects for no good reason

The only proper example I could think of would be if you're running a simulation and how fast the game runs affects the outcome
>>
File: I CAN BREAK THESE CUFFS.png (1MB, 1366x768px) Image search: [Google]
I CAN BREAK THESE CUFFS.png
1MB, 1366x768px
>>56079527
>tfw C++ wouldn't have the problem Mathematica has
>tfw Mathematica wouldn't have the problem C++ has
JUST
>>
>>56079684
>When you use side effects for no good reason
So it's just like in imperative languages!
But at least Haskell makes you annotate every single side effect so you can still pretend the language is pure while the runtime is actually not! ~ ~
>>
>>56079744
What are you talking about?
>>
>>56079506
explain yourself. runge-kutta is an iterative method which is supposed to give a different result on each step...
>>
In Rails models, does it make sense to check for
>validates :id, presence: true
if usually all models have an id that is auto-incremented anyway?
Would it still be useful in case something is added manually without an id?
>>
I'm making a game in C++ and I have a render function in my display class. I want to pass in the object that is being rendered, but only if it can be rendered. In C#, I'd make an interface called IRenderable or whatever, and that would be that; but of course that's not how it works in C++ short of deriving every single renderable object from an IRenderable class.

Is there some way can I pass this flag into an object and refer to it via polymorphism (i.e., not just a public bool variable)? Should I look into component-based design?
>>
>>56079781
>what is reading comprehension
I'm saying the code gives different results after each startup you mong. No shit it's iterative, what do you think root finding algorithms are?
>>
>>56076989
>>56077320
top kek, I'm fucking crying
>>
>>56079758
Wow you are SO silly Haskell-kun!
>>
What good is it to learn Haskell?
>>
>>56079826
>I'm saying the code gives different results after each startup
then explain yourself, this is completely unreasonable unless it's taking a different input from a file or something
>>
>>56079874
It is.
>>
>2016
>Still using monospace fonts
I only code in Microsoft Word
>>
>>56079874
none
>>
>>56078749
do it in Go instead. and yes, you can be sure of that.
>>
>>56079790
It doesn't make sense to validate id presence. Even manually added stuff gets an id.
>>
What good is it to learn Java?
>>
>>56079939
you can put on your resume that you know java
>>
>>56079933
>Go
No reason of existence
>>
>>56079882
Fuck if I know you fagbag.
>>
>>56079970
I didn't know that was a language feature
>>
>>56079979
still better than haskell
>>
>>56079979
you can easily average two integers in Go
checkmate anti-Go fags
>>
>>56080001
The OP talked about Rust.

>>56080011
False
>>
>>56079938
I see. Is that the case even someone adds something from the console and/or sets it to nil?
>>
Help me to learn C
I have this:
void someFunc(BYTE *inBuffer)
{
inBuffer = malloc(SOME_SIZE);
// fill inBuffer with certain data...
}

int main()
{
BYTE *myBuffer;
someFunc(myBuffer);

// do something to myBuffer...
free(myBuffer);
}


Obviously this doesn't do anything to the buffer at main, how would it do?
How are there functions that allocate memory to a buffer passed through a function?
Calling
inBuffer = malloc(SOME_SIZE);

seems to do nothing to the myBuffer pointer at the main function
>>
>>56080062
Pass-by-value, pass someFunc a BYTE**, deference it and, then malloc it.
>>
>>56080028
>False
disprove it. protip: you can't
>>
>>56080077
The Go integer types are not bignums or anything like that. They have limited number of bits preassigned to them.
>>
>>56080075
That worked thanks anon
>>
>>56080062
Way 1:
void someFunc(BYTE **inBuffer)
{
*inBuffer = malloc(SOME_SIZE);
// fill inBuffer with certain data...
}

int main()
{
BYTE *myBuffer;
someFunc(&myBuffer);

// do something to myBuffer...
free(myBuffer);
}


Way 2:
BYTE *someFunc(void)
{
BYTE *inBuffer = malloc(SOME_SIZE);
// fill inBuffer with certain data...
return inBuffer;
}

int main()
{
BYTE *myBuffer = someFunc(&myBuffer);

// do something to myBuffer...
free(myBuffer);
}


Also, why do you define BYTE? A char in C is a byte.
>>
>>56080062
Another idea is returning instead, like so:
BYTE* someFunc() {
BYTE *b = malloc(SOME_SIZE);
//....
return b;
}

int main(void) {
BYTE *mybuffer = someFunc();
}
>>
>>56080062
someFunc should take BYTE **inBuffer and you should call it like someFunc(&myBuffer).
>>
>>56080129
it might not be 8 bits though, maybe he defined it in such a way that it's always 8 bits
but then he'd name the type something to do with the amount of bits, rather than BYTE
>>
>>56080151
this and the caller of the function should initialize it, the function shouldn't call malloc
>>
>>56080154
1: if char is not 8 bits then nothing can be 8 bits
2: this is why (u)int8_t exists
>>
>>56080173
2. int8_t isn't guaranteed
>>
>>56080129
>>56080142
I did the first way like >>56080075

I define a BYTE because it's shorter and prettier than typing
unsigned char
everywhere

>>56080163
>the function shouldn't call malloc
Why not?
>>
File: 1455217692734.jpg (121KB, 2032x820px) Image search: [Google]
1455217692734.jpg
121KB, 2032x820px
>>56080187
>>
>>56080173
1. if a char is 4 bits than there can be things that are 8 bits, for example
>>
>>56080187
In which case BYTE will not exist.

>>56080201
A char can not be 4 bits.
>>
>>56080195
He wants you to do
BYTE *inBuffer = malloc(SOME_SIZE);
initBuffer(inBuffer);
>>
>>56076680
Blender has a motion tracking featureset.
Check out if they pushed any literature on the subject
>>
>>56080195
because you should be able to pass any pointer to it (such as a pointer to a segment of a static array) without having to worry about the function fucking it up and reassigning the pointer, and every malloc-free pair should be explicit by the user
>>
Any tools to use to pair program with friends online?
>>
>>56080286
git, or if you want to do it the meme way, https://codeshare.io/
>>
>>56080286
Frilly dresses and optional anal massage toys
>>
>>56079288
Get the reference manual from adobe's site (or buy a hardcopy version if you prefer).

It's such a niche language that you won't find many other resources.

It's good mental training and can occasionally be useful as a platform-neutral, language-neutral graphics API, but it mostly sucks as a language (ease of implementation was prioritised over ease of use).
>>
>>56080213
>>56080216
The problem is that the main function doesn't know the size the buffer will actually be
What will happen inside the function is seek into a file (passed as parameter) check if a block of bytes is compressed with some operations, if it is, then the decompress the block with LZ77 into the buffer, if not, it will just pass the whole block of bytes into the buffer.
In short, the size of the buffer will be determined inside the function.
Would it be good if I documented the function saying that whoever calls it should free the pointer?
>>
>>56080316
What does it need flash for?
>>
>>56080381
return a BTYE* instead of passing a BYTE**
>>
>>56080286
Tulpas.
>>
>>56080381
seems reasonable then
>Would it be good if I documented the function saying that whoever calls it should free the pointer?
yes
>>
>>56080423
The function returns an error code in case something goes wrong.
Does it make sense to receive an error code with a pointer/parameter?
>>
>>56080470
you could return NULL if there is only one error code
>>
>>56080423
Wait, if I do that, won't the function that called it have to free the pointer anyway?
>>
>>56080519
yes but if you have the byte** as a parameter, the implication is that the caller already has a buffer to write to, but you're mallocing in the function so it makes more sense to return a "fresh" pointer
>>
>>56080536
I'm pretty new to C so I didn't know it was bad to reassign a pointer. I'm taking this workflow is a terrible, terrible idea then?
int main()
{
BYTE *nextBuffer;

someFunc(&nextBuffer, fooA);
// do something to nextBuffer

someFunc(&nextBuffer, fooB);
// do something to nextBuffer

someFunc(&nextBuffer, fooC);
// do something to nextBuffer

free(nextBuffer);
}

I did some googling and didn't really get much info in reassigning a pointer in specific. I guess I should research more about malloc and free instead
>>
>>56080742
you should malloc nextBuffer, and THEN pass it to someFunc

it's got nothing to do with it being "bad" to reass pointers, that isn't a thing
you just have to learn good design is all

see >>56080129
>>
>>56076464
>tfw constantly bullied by scientists on a daily basis
>>
>>56080742
it could be problematic since it's not easy to know what nextBuffer is between calls to someFunc, this is why java is strictly pass-by-value
>>
>>56080768
The main function doesn't know which size the buffer is gonna be.
I'll go with using different variables + >>56080423 + >>56080448
instead then
>>
>>56080536
No. That is not correct a signature of
 void func( sometype ** _param )
explicitly allows current function to reassign the memory. Consider this
 void func( sometype * _param )

explicitly states that you can write to _param and it will be propagated outside of 'func'. Now consider
typedef int * sometype
void func( sometype * _param )

since _param is writable, and sometype is a pointer, then func can write to a pointer - reallocing the memory.
>>
>>56080953
touche
>>
>>56080742
void someFunc( BYTE ** buffer, int parameter );

int main()
{
BYTE *nextBuffer = NULL; // always initialize variables!

someFunc(&nextBuffer, fooA);

if( nextBuffer != NULL )
free( nextBuffer );

nextBuffer = NULL;

someFunc(&nextBuffer, fooB);

if( nextBuffer != NULL )
free( nextBuffer );

nextBuffer = NULL;

someFunc(&nextBuffer, fooC);
// do something to nextBuffer

if( nextBuffer != NULL )
free( nextBuffer );
}


Also consider, that if main allocated something to nextBuffer, then you need to check if the memory pointer by nextBuffer has changed in someFunc, and if necessary free it as well. C++ with smart pointers makes this mess much easier, btw.
>>
>>56081040
is there a reason why you're using BYTE instead of unsigned char?
>>
>>56081064
>unsigned char
>not uint8_t
>>
File: transform.gif (3MB, 360x404px) Image search: [Google]
transform.gif
3MB, 360x404px
Guess that matrix!
>>
>>56081074
char is always 8-bits
the standard demands it
>>
>>56081086
sizeof(char) is always 1 but CHAR_BIT can be more than 8
>>
>>56080953
>>56081040
I see, thanks a lot.
I'm porting a Java project into C in order to learn C but sometimes I miss not having to care what happens to memory since the GC will hold my hand anyway

>>56081064
I'm just lazy to write unsigned char and BYTE seems neater. Bad practice?
>>
>>56081064
The guy whom I am replying to used BYTE. I'd use 'uint8_t' or just 'char' and be done with it.
>>
>>56081074
uint8_t is optional

>>56081086
Fucking retard
>>
Attempting Problem 8 of Project Euler with D, it is not liking my answer though ;_;

Code: http://pastebin.com/ae7ncdRn

https://projecteuler.net/problem=8

My answer: 1792336896
>>
>>56081103
>>56081112
if you're working with binary data i'd typedef unsigned char to "byte".
>>
>>56081125
>uint8_t is optional
see >>56080197

also
typedef unsigned char uint8_t;
>>
>>56081150
>also typedef unsigned char uint8_t;
This is wrong
>>
>>56081163
???
>>
>>56077261
Create read update delete. What 90% of programmers do at their job.
>>
>>56081103
>>56081125
>>56081134
>>56081150
>>56081163

Being pedantic in regards to software is pointless. Just about 99.9% of platforms which have a C compiler has 8 bit 'char' type. I prefer to be explicit in my code, so no unnecessary typedefs, but in reality _it does not matter_ production code either works, and nobody gives a shit as long as it does, or fuck up and autistic deliberation of which type to use is just loss of valuable employer time.
>>
>>56081193
redefining shit that the standard already defines is UB
unsigned char may not be 8 bits
unsigned char is not necessary to be the same type as uint8_t so implying that they are the same is wrong.
>>
>>56081134
I'm working with binary data, but is there any difference between unsigned char and uint8_t?
Specially when you mention binary data
>>
>>56074913
Stop being retarded anon you get what i mean. There's nobody doing anything but maintenance in the language so there's no forces interested in developing (good) software to support the language.

It's plainly obvious.
>>
>>56081219
you can choose to understand
>>
>>56081083
They're all affine transforms when you get down to it.
>>
>>56081228
there is none

it's just visual reinforcement for whoever's reading your code
something like
byte arr[] = {0x00, 0x32, 0xFF};
makes it very clear you're writing binary data.
>>
>>56080000
chek'd
>>
File: >being a gentile.jpg (78KB, 393x700px) Image search: [Google]
>being a gentile.jpg
78KB, 393x700px
When did you realize Pokemon Go was literally a CIA operation?

I'm not even joking- Putin literally banned it

O I M laffin
>>
>>56081245
And affine transforms are linear if your high-school math teacher is to be believed.
>>
File: Screenshot_2016-08-14_15-56-21.png (88KB, 864x85px) Image search: [Google]
Screenshot_2016-08-14_15-56-21.png
88KB, 864x85px
>>56081128
Whoops, y should be initialized to 13, but now I'm getting numbers that shouldn't even be possible
>>
>>56077320
Lost
>>
File: tumblr_n4o7uo8vVt1qjjrq2o1_400.jpg (29KB, 350x250px) Image search: [Google]
tumblr_n4o7uo8vVt1qjjrq2o1_400.jpg
29KB, 350x250px
>>56081302
CIA?
>>
>>56081316
In a real language: http://pastebin.com/C7PKi32b.
>>
>>56081430
D is a real language though
>>
>>56081483
Then show us your solution to problem 8 :^)
>>
what do winfags use to program in C?
>>
>>56081507
Well, that's what I'm trying to figure out, innit?
>>
>>56081512
VS
>>
>>56081512
emacs + gcc
>>
>>56081512
3 choices

1. VS, Even though it doesn't even fully support C99, all you really need is C89
2. GCC on Cygwin
3. MinGW
>>
where do I find the answers to project euler?
not the code, the output of the code
>>
>>56081588
On your own
>>
>>56081622
how do I check if it's correct?
>>
>>56081630
By entering what you get on the problem page, it'll tell you.
>>
>>56081630
Enter it and see what the site says. You have to log in to do that though
>>
>>56081648
>>56081643
ah thanks
>>
Have you ever felt disillusioned with it all, /dpt/? Regretting ever thinking about getting a job in programming?
>>
>>56081552
I tried this but it seemed super bloated, like 40GB install size. Is that normal? Also, am I supposed to download some plugins for C support? Or just pretend that i'm writing c++?

>>56081556
>>56081583
i tried gcc on cygwin but it seems to be a pain in the ass to get it working smoothly with the system. Like if i launch my .exe from within cygwin it's fine but if i do it from the windows cmd prompt then it gives me an error that a .dll is missing. Is that somehow to be expected or did something go wrong on my system?

Thanks.
>>
File: 1470347909817.jpg (176KB, 600x641px) Image search: [Google]
1470347909817.jpg
176KB, 600x641px
Can someone please help me figure out how to compile this?

I just want to print the value of MBEDTLS_VERSION_NUMBER why does C make things so fucking difficult.

#include <mbedtls/version.h>
#include <stdio.h>

main() {
printf(MBEDTLS_VERSION_NUMBER);
}
>>
>>56081777
you probably want
printf("%d\n", MBEDTLS_VERSION_NUMBER);
>>
>>56081777
you need to link the mbedlts library
it might be -lmbedtls but maybe not
google it
has nothing to do with C btw
>>
>>56081777
The first argument of printf has to be a NULL-TERMINATED BYTE ARRAY (a string).
>>
>>56081802
>>56081777
fucking kek

also
>main()
>>
>>56081755
>Like if i launch my .exe from within cygwin it's fine but if i do it from the windows cmd prompt then it gives me an error that a .dll is missing
make sure *cygwin install directory*/bin is in your path
>>
>>56081083
[1 0 0]
[0 1 t]
[0 0 1]
>>
>>56081314
Well, they are linear if you use homogeneous coordinates.
>>
>>56081777
>>>/g/wdg
>>
>>56081818
I was gonna say yep i did that but then I checked again and I had C:/Cygwin64/bin instead of C:/cygwin64/bin. I don't think it's case-sensitive though right?
Anyway i tried again and now it seems to work when i double-click on the .exe, but it still gives me the error if i try to launch it from the windows cmd prompt. That's expected though right? So if I want to launch the program via shell i need to use cygwin but if I use the mouse then the system takes care of it automatically?
>>
>>56081228
> is there any difference between unsigned char and uint8_t?
Not on any platform you're likely to encounter.

If uint8_t exists, it's guaranteed to be exactly 8 bits. unsigned char is only required to have at least 8 bits (but architectures where it's more than 8 bits are either obsolete or DSPs).
>>
>>56081228
char is guaranteed to be the smallest unit of memory (a "byte"), which is not guaranteed to be 8 bits, unless you're using a computer that has been remotely relevant within the last 50 years.
That means if you're manipulating memory as sequences of bytes, use 'char', but if you're manipulating memory as sequences of 8-bit objects, use [u]int8_t.
>>
>>56081228
unsigned char is portable
>>
>>56082085
>>56082189
you should use uint8_t for example when reading files, if the implementation doesn't have 8 bit bytes you're fucked anyway so it's better to catch it at compile time
>>
File: transform.gif (2MB, 360x404px) Image search: [Google]
transform.gif
2MB, 360x404px
>>56082010
Yep. Have another.

>>56082043
Good point.
>>
>>56082189
Honestly, I don't care that much about portability because I only intend for my program to run on the platform I write it on.

If you masturbate over portability but then never compile it for any platform except one, what have you accomplished?
>>
>>56082229
portability
>>
>>56082207
file io is using unsigned char
>>
>>56082229
>I only intend for my program to run on the platform I write it on
then unsigned char is perfect
>>
>>56082214
I can't even tell what's happening with the y plane
>>
>>56082229
The distinction I was trying to make >>56082188 is that typing can give clues into context.

e.g.
char _static_pool[1024];
char* memory_pool = _static_pool;
void* pool_take (size_t siz)
{
char* ptr = memory_pool;
memroy_pool += siz;
return ptr;
}
/* appropriate to use 'char' because we are dealing with lowest memory units, also because sizeof() returns # of chars */

inline uint32_t le (uint8_t a, uint8_t b, uint8_t c, uint8_t d)
{
#ifdef ARCH_LITTLE_ENDIAN
uint8_t punme[4] = {a, b, c, d};
return *(uint32_t*) punme;
#else
return a |
(b << 8) |
(c << 16) |
(d << 24);
#endif
}
/* appropriate to use 'uintN_t' because we are concatenating specific numbers of bits */
>>
>>56082229
>masturbate over portability
The only thing that has made C so successful is portability
>>
>>56082402
No. What made C successful is its speed and its relative ease of producing machine code compared to asm.

The C language itself is the same between platforms, but their standard library implementations differ, and where they do the code is usually not quite portable.
>>
>>56082313
>#ifdef ARCH_LITTLE_ENDIAN
worthless
>>
New thread: >>56082496
>>
File: post.png (200KB, 1600x528px) Image search: [Google]
post.png
200KB, 1600x528px
I just started taking cs50 and I'm only up to week 2, while I'm having a blast it became pretty clear the PDF of Programming in C I was working off of just wasn't gonna cut it anymore. So I got a copy of Programming in C 4th edition, the SICP, and I'm thinking of picking up Concrete Mathmatics, and Clojure for the Brave & True (I like LISP) What's a good text for a novice programmer who's been writing really small programs for a long time, but finally wants to git-gud?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import turtle
import random

#setup the display, configures background color
wn = turtle.Screen()
wn.bgcolor("black")

#creates all the turtles and crams them into a list
artists = [turtle.Turtle() for x in range(10)]

#generates rotational angles and movements
move = [random.randrange(40,60) for x in range(10)]
rotate = [random.randrange(0,360) for x in range(10)]

#Configures turtle color
colors = (
"Red","Blue","Purple","Brown","Gold",
"DarkKhaki","OrangeRed","DarkSlateGray",
"MediumSpringGreen","ForestGreen"
)
for artist, color in zip(artists, colors):
artist.color(color)

#set up the turtles to draw the shapes
for a in artists:
a.speed(0)
a.ht()
a.penup()
a.right(random.randrange(0,360))
a.forward(125)
a.pendown()
for i in range(120):
for x in range(0,9):
artists[x].left(rotate[x])
artists[x].forward(move[x])
wn.exitonclick()

This is about the most complicated program I've written to date
>>
>>56082214
The xz plane is being flipped in sign, and the xy and yz planes are swapped, so it should be something like
[0  0 1]
[0 -1 0]
[1 0 0]
>>
>>56082538

It's not the number of books.


1. Just work (not just read!!) yourself through SICP to learn Scheme.

2. Do a couple of the excercises from the /g/ programming challenges.

3. Think of a cool idea for a project and build it.

4. Repeat 1-3 with some other books (K&R, some Java 8 book, Haskell.. doesn't even matter) until you know 3-5 languages.

5. Work with some Frameworks/Libraries of your favorite language.


This should take you some time.
Thread posts: 313
Thread images: 34


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