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

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

Thread replies: 255
Thread images: 23
File: 1454910804310.png (17 KB, 1041x148) Image search: [Google]
1454910804310.png
17 KB, 1041x148
Previous thread: >>52909920

What are you working on, /g/?
>>
Why don't I want to do anything? I miss working on projects.
>>
>>52916128
start a new project or revisit an old one so you have something to do
>>
>>52916139
What project?
>>
>>52916128
Make something useful for yourself.
>>
>>52916157
What if I don't need anything?
>>
>>52916161
Make a game.
>>
>>52916188
What if I don't like games?
>>
>>52916205
Why don't you like games?
>>
>>52916128
>>52916161
I know that feel. When I was 16 I could spent months on useless projects having fun and gaining experience, now I'm a professional programmer and I have some free time, so I'd like maybe to spend that time on my own projects, but I don't need anything, I'm not interesting in anything, and most of useful software are already written, so I just play vidya on my weekends.
>>
>>52916205
Music/video organizer? Really, I'm sure you can think of something to automate.
>>
https://stackoverflow.com/questions/30365346/what-is-the-spaceship-operator-in-php-7

>spaceship operator
lol
>>
>>52916230
I do need something to organize my vast collection of porn
>>
>>52916231
Did they fix the ternary operator yet? Or the inconsistent naming of library functions?
>>
File: persuasion.webm (2 MB, 640x360) Image search: [Google]
persuasion.webm
2 MB, 640x360
Ask a programming literate anything.
>>
Working on a program that takes in a whole bunch of statistics and then sorts the data according to one stat.

My biggest issue is I have everything in a struct, and so I'm trying to figure out the best way sort based on a user specified field. I.E. Stats[].field. I'm really just trying to think of a better way to do this without if statements for matching each field.
>>
>>52916240
How about some image tagging GUI program?
>>
>>52916257
What project should I do?
>>
File: kissu.webm (3 MB, 1280x720) Image search: [Google]
kissu.webm
3 MB, 1280x720
>>52916317
programming language implementations benchmark.
>>
>>52916317
infix to lisp converter
pretty print it too
>>
>>52916345
Weeb senpai,ever done a multicore benchmark with languages like Go and Elixer?
>>
File: alimony.jpg (184 KB, 837x892) Image search: [Google]
alimony.jpg
184 KB, 837x892
Can anyone help me figure out why VS2015 is having an issue?

I have a solution which consists of two projects: a static library (the main point of the solution) and a console program that tests the library. The static library links against libFLAC. I've built libFLAC already; it compiled fine and generated a .lib file. The library I'm writing also compiles fine and generates a .lib file without any compiler warnings or errors. However, the console program gives me a LNK2001 error (unresolved external symbol __imp__FLAC_stream_decoder_init_stream and so on).

Now, both the library and the console program have the directory that contains libFLAC_static.lib in their library search path, and have libFLAC_static.lib as a dependency. The console program also has the directory that contains the .lib file generated by my library, and has the file as a dependency. What is VS2015 trying to tell me?
>>
>>52916257
which amine is that??
>>
>>52916537
Try including the lib file in the additional dependencies in the linker settings or something
>>
File: Untitled.png (33 KB, 1030x699) Image search: [Google]
Untitled.png
33 KB, 1030x699
>>52916565
Yeah, I've done that, I guess I didn't make that clear enough in my post.
>>
>>52916537
I ran into one problem with GLEW where I didn't define something to say I wanted static compilation. Maybe it's that?
>>
Okay, I started studying C++ and would like to ask what software do I use to program on?

[spoiler]preferably free[/spoiler]
>>
>>52916257
What is your experience?

And why do you call yourself literate?
>>
>>52916636
vim
Normies can use QtCreator.
>>
>>52916642
>And why do you call yourself literate?

He knows the answer to every programming question.
>>
>>52916602
Could be. The problem is that I don't know what to define or where to define it. But I'm pretty sure that if you choose to make a static library when creating a project, it automatically does that.
>>
>>52916665
*wikipedia knows the answer to every programming question.
>>
>>52916537
http://lists.xiph.org/pipermail/flac-dev/attachments/20101117/c1b8737c/attachment.txt
>>
>>52916679
This is so far off.
>>
>>52916665
no he doesn't
>>
trying to increase my c knowledge.

I'm trying to understand the purpose of double pointers, why would you want a pointer to a pointer? What does this achieve over normal pointers?
>>
>>52916755
void alloc_int_arr(int **arr)
{
*arr = malloc(sizeof(int) * 100);
}
>>
>>52916755
When you want a dynamically allocated multidimensional array.
>>
>>52916755
There are a couple reasons. Functions will often take double pointers when they need to set the value of the pointer itself (rather than the value of the underlying type).
>>
>>52916679
*stack overflow
>>
>>52916755
http://wordaligned.org/articles/two-star-programming
>>
>>52916782
>>52916786
>>52916799
So when your function needs to allocate the pointer memory? Why not pass a null pointer then just allocate that?

>>52916851
Thanks for the link, I'll give this a read.
>>
>>52916894
>2016
>allocating null pointers
>>
>>52916894
> Why not pass a null pointer then just allocate that?

wat
>>
>>52916755
From Stackoverflow, a funny answer (although not complete) :

If you want to have a list of characters (a word), you can use char *word

If you want a list of words (a sentence), you can use char **sentence

If you want a list of sentences (a monologue), you can use char ***monologue

If you want a list of monologues (a biography), you can use char ****biography

If you want a list of biographies (a bio-library), you can use char *****biolibrary

If you want a list of bio-libraries (a ??lol), you can use char ******lol
>>
>>52916894
Because you want to modify the CONTENT of the pointer, not the pointer itself.
>>
>>52916894
>So when your function needs to allocate the pointer memory?
No, it's typically modifying an existing pointer to somewhere else (e.g. via realloc), or to initialise a pointer that already exists.
The best example I can think of is the POSIX function getline(). It's a great example of pointers to pointers.
>>
>>52916755
why do you need "normal" pointers? why do you need pointers at all?
if you can answer that, it's easy to see why you also could use double/triple/etc pointers
>>
>>52916894
>Why not pass a null pointer then just allocate that?
Setting the value of a pointer in a function won't change the value of the pointer outside of the function, it will only change the value underlying the pointer. So if you have an int, and pass the function a pointer to that int, then it can change the value of the int. If you have an int *, and pass the function a pointer to the int *, then it can change the value of the int *.
>>
>>52916755
2D array, array of strings, etc.

>>52916799
This is the other non-obvious use I've seen. Particularly useful in concurrent data structures, pointer updates can be made atomic and doing so doesn't invalidate any pointers to the old structure current readers might have.
>>
problem: got 2 ints; need average; what do?
>>
>>52916662
First time using vim.

Any good guides on how to use it?
>>
>>52916962
vimtutor
>>
>>52916799
>underlying type
>muh made up shit
>>
Trying to go through Lets build a compiler.

I tried porting the 68k asm code to x86, and it worked up until now, but I kinda got stuck on chapter 3 when variable declaration was introduced.
Can you even declare variables outside of the .bss/.data sections in x86?
>>
>>52916755
let's dumb it down to:
why do you need pointers? to point at things; why do you need pointers to pointers? because pointers are things.
>>
>>52916205
Well if you absolutely don't know what you wanna make, you could always kill yourself.
>>
>>52916974
>what is .rodata
>what is .text
>>
File: 1431432030106.jpg (13 KB, 228x238) Image search: [Google]
1431432030106.jpg
13 KB, 228x238
>>52917007
>allocating variables in .text
>>
wow, i didn't expect this much of a response. thank you all.

>>52916898
>>52916909
As you can probably tell, I don't really know what I'm talking about.

>>52916913
>>52916930
This makes sense, I'll play around more with it.

>>52916922
I'll check out the source of that, thanks anon.

>>52916926
Well, it makes sense for a single pointer because you don't want to keep passing around large values through out your code. A pointer to said object is way easier to work with. Im not really sure how double pointers follow from that (before I posted).
>>
File: 1445511667448.gif (1 MB, 320x180) Image search: [Google]
1445511667448.gif
1 MB, 320x180
some needs to make a CPack generator for creating an autotools package/tarball/whatever
[spoiler]yeah i know its more or less impossible, but it would be the final nail in the coffin for autopain[/spoiler]
>>
>>52917007
Yes, yes, I'm trying to learn x86 assembly as I go through the book as well, so I missed those two. But to be more specific, I wanted to know if you could declare variables right in the code.
>>
>>52917024
>because you don't want to keep passing around large values
that's it? how about changing the value of an argument to a function? how do you do that?
you need to change an int? you pass it's address as an int* and change it "*x = y;"
you need to change a pointer to int? you pass it's address as an int** and change it "*x = &y;"
>>
>>52916802
SO only has a currynigger tier understanding of things
>>
>>52917024
>Im not really sure how double pointers follow from that (before I posted).
You have a function (A) that returns a reference to an object. You want to update that object, put a new object in it's place, so you free the old object and make function A return the new object. All the functions that called function A previously to get the reference now have an invalid reference. If they don't know you get errors, if they do somehow they will need to call A again to get the new object reference.

If function A returns a pointer to a pointer you can update the internal pointer to the object without invalidating all the pointers A gave out. So you invisibly update all the objects from under the holders without some convoluted scheme to make them call A for a new object when the old one gets invalidated.

Also 2D arrays and array of strings: char **argv for instance.
>>
>>52917047
autopain, cshit, it's all the same
just use fucking make, why the fuck do you need build tools that generate build tools
next thing you know you'll be asking for a new meta-tool that generates cmake shit in order to generate makefiles
>>
>>52917081
There are plenty of very competent programmers that answer on SO.

There really isn't any other comprehensive Q and A website for programming.

There's lots of pajeet, but usually those are the ones asking the questions, which subsequently get voted down within 2 minutes.
>>
File: Honeycam 2016-02-11 21-39-43.gif (2 MB, 1280x720) Image search: [Google]
Honeycam 2016-02-11 21-39-43.gif
2 MB, 1280x720
Game Programming.
>>
>>52917099
>just use fucking make
make isn't portable enough you nigger
>>
>>52917024
all you need to realize is that pointer types are not magic pixie dust; they're just like other types

my_type get_value();

void modify(my_type *x)
{
*x = get_value();
}

you can "typedef int my_type;" or "typedef int *my_type;" and the logic of the code is the same; pointers are normal objects, just like ints, floats, etc.
>>
>>52917147
gnu make is available everywhere
>>
>>52917147
>cmake is more portable than gnu make
sure thing, pajeet
>>
>>52917122
they're tend to be pseudonormie spergs that spout memes like
>premature optimization is the root of all evil
>>
>>52917133
Cool to see you posting here again South Korean dude. I noticed you haven't pushed anything to GitHub. Doesn't matter, it takes time to do something right.
>>
>>52917173
>>52917182
on unix, sure
not useable on windows without cygwin, which is massive pain in the ass
>>
>>52917204
O_o sorry It's quite difficult to adopt Box2D X(..
Box2D is really good stuff but It's still shit.
I'll push my work soon when I finish this work. ;)
>>
>>52917227
please, educate yourself
>>
>>52917272
Holy shit kill yourself.
>>
>>52917309
fuck off
>>
>>52917133
dat framerate doe
>>
>>52917283
>im getting rekt so ill just call him uneducated
get fucked
>>
>>52917272
I haven't used Box2D myself, but I've seen it working in a production program in iOS and Android. Shit's pretty neat senpai. Good luck with your program.
>>
>>52917227
>he doesn't have msys2 installed on his windows box
>>
>>52917315
I implements constant game speed that independent of variable FPS with frame interpolation so It's originally over 60fps
But I used a gif capture program so It occurs framerate loss you dumbass cunt
>>
>>52917363
it seems to freeze up when you spawn characters, it's disgusting to have huge lag spikes like that
>>
>>52917324
>I don't know how to use gnu make
that's your problem
>>
>>52917388
I see. I had implement the game using single thread.
message procedure and game logic processes in same thread so that have quite heavy cost I think.
>>
>>52917443
no, pajeet, you're just bad at this
>>
File: cpp-ogl-monkey.webm (976 KB, 1920x1080) Image search: [Google]
cpp-ogl-monkey.webm
976 KB, 1920x1080
I just succeed in positioning light in my progam.
>>
>>52917334

I've tinkered with Box2D via CF2.5, and it's breddy neat.
>>
>>52918124
>cf2.5
What's that? ColdFusion 2.5?
>>
>>52918152

2D game development software, Clickteam Fusion.
>>
>>52918158
Kinda like GameMaker or Unity?
>>
A pointer is just an address that points to a location in memory. Do not think of pointers as objects they are no different than a 4 byte integer except its value is used to point to a memory location
>>
>>52918273
Hi Dan.
>>
>>52918273
They are different though.
uint32_t a = 10;
a++; // a == 11 now

int x = 10;
uint32_t* a = &x;
a++; // a == &x + 4 now

> 4 byte integer
intptr_t integer, actually.
>>
>>52917810
monkey looks gay, and dumb. worst opengl progarm i've seen.
how's the vba/vbo/etc stuff treating ya?
>>
>>52918273
they can be 8 bytes you fag
>>
>>52918384
it's the standard monkey to use when learning opengl what the fuck you talking about
>>
>>52918542
He's jealous about your monkey.
>>
File: eye.webm (325 KB, 498x498) Image search: [Google]
eye.webm
325 KB, 498x498
How does it look /g/?
>>
What's the best Java book?
>>
>>52918615
Qu'ran. Next question.
>>
>>52918334
>intptr_t integer, actually.
1) intptr_t might not exist
2) might not have same representation
3) might have different size
basically, there's no relationship between pointers and integers
>>
>>52916911
Easy way to visualize multi-dimensional arrays.
*line
**page
***book
****shelf
*****bookcase
******library
*******all_libraries_on_planet
********all_planets_with_libraries_on_them
*********what
>>
>>52918526
they can be 12 bytes, fgt
>>
Why would you want to use a normal lock over a reentrant lock?
>>
>>52918653
those are not C multi-dimensional arrays
>>
>>52918677
maybe you don't need a reentrant lock, just need the same as mutex lock..unlock
>>
What's the deal with that OP pic.. Is he using retard to mean autist? Tough to believe he's an actual retard, but maybe I just associate the word with the worst of the worst retards.
>>
>>52918715
idk but you can be pretty damn stupid and still function in society. and the worst autists (not high-functioning) are as fucked up as the worst retards
>>
>>52918684
all_planets_with_libraries_on_them[1][2][3][4][5][6][7][8];
/* column 8, row 7, book 6, shelf 5, bookcase 4, library 3.... */
>>
>>52918648
> 1) intptr_t might not exist
Stop using C89, grandpa.
> 2) might not have same representation
Doesn't matter.
> 3) might have different size
It's guaranteed to have enough size to hold a pointer, it's all you need to know.
> there's no relationship between pointers and integers
Tell it to ptrdiff_t.
>>
>>52918677
1) it's often cheaper
2) to avoid bugs; if the code doesn't expect the lock to be re-entrant, shit can go sideways
shared_lock.lock();
shared_state->size = compute_new_size();
shared_state->ptr = grow_to_size(new_size);
shared_lock.unlock();

if grow_to_size does lock()/unlock() thinking it can freely mess with shared_state in the locked region, you're gonna have a bad time when you replace the lock with a re-entrant one; with the non-reentrant one, the deadlock will help you find the bug sooner
>>
Is there any design pattern that notice when a object changed?
>>
>>52918873
the observer pattern
>>
>>52918786
>Stop using C89, grandpa.
start reading C11, intptr_t is optional
>Doesn't matter
>It's guaranteed to have enough size to hold a pointer
the claim was that the size of the pointer is the size of an intptr_t; that's false
>Tell it to ptrdiff_t
ptrdiff_t already knows that; you're the one lacking enough C knowledge
>>
>>52918883
Observer pattern can apply to every method? I can't get it how it works
>>
>>52918786
>Stop using C89, grandpa.
Shut the fuck up kiddo. C89 is the industry standard.
>>
what's a good way of learning software patterns without getting lost or falling asleep?
>>
>>52916782
This is bad practice.
Don't do this.
>>
How does this make you feel, /g/?
cube_t *create_cube(unsigned x, unsigned y, unsigned z)
{
cube_t *ptr = malloc(sizeof(cube_t));
ptr->size.x = x;
ptr->size.y = y;
ptr->size.z = z;
unsigned i, j; /* make 3D cube */
ptr->cube = malloc(sizeof(unsigned char **) * x);
for (i = 0; i < x; i++)
ptr->cube[i] = malloc(sizeof(unsigned char *) * y);
for (i = 0; i < x; i++)
for (j = 0; j < y; j++)
ptr->cube[i][j] = malloc(sizeof(unsigned char) * z);
return ptr;
}
>>
>>52918832
But is this really a problem related to concurrency?
If grow_to_size makes assumptions about shared_state and then acts on the base of these assumptions, it's gonna fuck up when executed sequentially as well.
Assuming I only have
shared_state->size = compute_new_size();
shared_state->ptr = grow_to_size(new_size);

without locks inside of grow_to_size, doesn't the problem persist in exactly the same way?
>>
File: Y4RZmQf.png (80 KB, 529x327) Image search: [Google]
Y4RZmQf.png
80 KB, 529x327
>>52919018
>How does this make you feel
>>
>>52918665

They're 16 octets on 128-bit RISC-V.
>>
>>52919046
>If grow_to_size makes assumptions about shared_state
the assumption it makes is that it can change it after obtaining the lock to do so; wouldn't you change shared state after obtaining a lock? that's the entire purpose of locking: it gives you temporary exclusive ownership on a shared resource
>without locks inside of grow_to_size
if you don't have a lock, you don't touch the shared state either, no?
>>
>>52919000
anyone?
>>
>>52919243
There is none.
Programming requires lots of reading.
If you can't pay attention while reading for more than 2 seconds, just go back to watching anime.
>>
>>52919260
Seconded.
>>
Remember you can get it in the AUR now
>>
>>52919260
I don't watch anime...
I also don't read about programming as much as I should, desu. things usually make sense to me. I kinda understand why you'd want this or that way of doing things (or not), but concepts, or the words used to express them, make things tedious...
I ask this because I'm a uni drop-out, and want to keep learning by myself.
>>
>>52919377
>uni drop out
>couldn't learn in a structured environment
>thinks he can learn without reading any theory
just kill yourself, fucking neet
>>
>>52919217
>they might be
ftfy; RISC-V only defines the RV32 and RV64 ABIs; RV128 doesn't have a C ABI yet
>>
>>52919408

No ABI is defined, but nonetheless, 128 bits of memory are addressable in the ISA. It stands to reason that a pointer in C would need to be at least 16 bits, and probably not more, because you'd be retarded to want them larger.
>>
>>52919461

At least 16 bytes*. Fucking morning brain missing this shit.
>>
File: vis.webm (2 MB, 1020x688) Image search: [Google]
vis.webm
2 MB, 1020x688
I made a visualizer thingy
>>
For a school thing I've been given this class with these methods: http://pastebin.com/T6a74XQe

I'm suppose to write the nextMonth() method only, but I can't seem to figure it out with the other methods I've been given. How can I figure out the current month if the outputMonthNumber method returns void and just prints it out to cout?

Month next = testMonth.nextMonth();

How exactly is this suppose to work if theres no way to get an int corresponding to the current month to then increment for the next month? With outputNextMonth returning void, and not int, this seems either impossible or highly convoluted to the point if ridiculousness.
>>
>>52919461
>>52919475
not really; they could still be 64 bits, because that's an insane amount of address space anyway
128-bit pointers would be a waste, since we don't even use 64-bits yet (the original amd64 launched with 40-bits (1TB) of address space, current ones are 48-bit (256TB) and the next step would be to extend to 52-bits (4PB) but it's uncertain when/if that will happen)
why would anyone want 16-byte pointers when ~10 of those bytes would be always 0?
>>
let's see how you fags would implement this:
https://www.hackerrank.com/challenges/c-tutorial-for-loop
>>
>>52919612
I want to fuck that visualizer
>>
>>52919641
>current ones are 48-bit
Is it the dumbest idea in the world to stuff data in those spare 16 bits? Obviously they would be masked out when referencing.
>>
>>52919693
impossibru
>>
>>52919718
probably; you'd have to mask them by hand (ie, in software), the CPU doesn't ignore them, it actually enforces for all of them to be either 0 or 1
>>
>>52919693
A fucking table lookup, a couple branches, a loop. How else would you implement it in C?
>>
>>52919693
can't be done, anon
>>
>>52919721
I know it's a difficult task but I know /dpt/ is up to the challenge. I've been looking at some of the leaderboard answers and I'm lmaoing at their lives.
>>52919750
Go to C++, go to leaderboard, look how the guy (girl?) who has #1 did it. actually I'll just post it.

#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main() {
vector<string> arr;
arr.push_back("zero");
arr.push_back("one");
arr.push_back("two");
arr.push_back("three");
arr.push_back("four");
arr.push_back("five");
arr.push_back("six");
arr.push_back("seven");
arr.push_back("eight");
arr.push_back("nine");
int a, b;
cin >> a >> b;
for(int i = a;i<=b;i++){
if(i > 9){
if(i % 2 == 0) cout << "even" << endl;
else cout << "odd" << endl;
}
else cout << arr[i] << endl;
}
return 0;
}

L O L
>>
>>52919762
looks bretty gud
>>
>>52919746
>the CPU doesn't ignore them, it actually enforces for all of them to be either 0 or 1
>enforces
How? Is it trapped?

>>52919762
>look how the guy (girl?) who has #1 did it.
That shit's retarded.
>>
>>52919237
Okay, I got it now after researching a couple of other examples as well.
"The issue is being able to reason locally about code. People (at least me) are trained to recognize locked regions as invariant maintaining, that is at the time you acquire the lock no other thread is modifying the state, so the invariants on the critical region hold. This is not a hard rule, and you can code with the invariants not being held in mind, but that would just make your code harder to reason and maintain. The same happens in single threaded mode without mutexes, but there we are not trained to reason locally around the protected region."
This pretty directly adresses my question.

Also, another interesting issue regarding reentrant locks:
"The biggest of all the big problems with recursive mutexes is that they encourage you to completely lose track of your locking scheme and scope. This is deadly. Evil. It's the "thread eater". You hold locks for the absolutely shortest possible time. Period. Always. If you're calling something with a lock held simply because you don't know it's held, or because you don't know whether the callee needs the mutex, then you're holding it too long. You're aiming a shotgun at your application and pulling the trigger. You presumably started using threads to get concurrency; but you've just PREVENTED concurrency."
>>
>>52919797
Yeah.
Mine probably isn't that better, I just started with C++ and I'm sort of still treating it like C.
#include <iostream>

int main (void) {
int a, b, i;
char names[][6] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
std::cin >> a >> b;
for (i=a; i<=b; i++) {
if (i<=9) {
printf("%s\n", names[i-1]);
} else {
printf("%s\n", i > 9 && i % 2 == 0 ? "even" : "odd");
}
}
return 0;
}
>>
>>52919762
>elitists in /dpt/ can't do this
"elite" programmers itt amirite
>>
>>52919693
their output makes no sense, i'm not even going to attempt it
>>
>>52919762
push_back
push_back
push_back
push_back
push_back
push_back


Jesus, just use a DESIGNATED initialization list.
>>
>>52919824
You don't need to declare your variables at the top. Use cout instead of printf. Use string instead of char *. Now it's official C++ idiomatic.
>>
>>52919868
how about i initialize my FIST into your FACE
>>
>>52919876
bu..but this tutorial just said when you're dealing with a lot of numbers (which I know we aren't in this scenario) you should use printf because it's faster. I did totally forget about string though. At least I'm not using namespace std though rite?
>>
>try making a minesweeper a couple of days ago
>literally feel like a retard because this shit's supposed to be easy for me
>try it again today
>goes smooth as my ass
have you had periods where you felt like a complete retard?
>>
>>52919894
>you should use printf because it's faster.
It's not C++ idiomatic to care about speed differences.
>>
>>52919905
Every time I read a /dpt/.
>>
>>52919693
#include <iostream>
#include <vector>
using namespace std;

int main() {
vector<string> nums = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int a,b;
cin >> a >> b;
for (int i=a; i<=b; ++i)
cout << (1<=i && i<=9 ? nums[i] : i%2==0 ? "even" : "odd") << endl;
}
>>
I'm using C++ for the first time in a decade and apparently I don't understand how references or possibly vectors work. I have an object "Semnet" that contains a vector of structs as a member and I'm trying to take a reference to one it contains.

std::string Concept::as_str() const
{
std::ostringstream os;
os << std::setw(4) << this->id << " "
<< std::setw(4) << this->info.text << " "
<< std::setw(4) << case_str(this->info.gcase) << " "
<< std::setw(4) << "[" << this->down.as_str() << "] "
<< std::setw(4) << this->print_flags();
return os.str();
}

Concept& Semnet::new_concept(unsigned int flags, const LangInfo& info)
{
auto id = this->all_concepts.size();
this->all_concepts.emplace_back(Concept(id, info, flags));
return this->all_concepts.back();
}

Concept& Semnet::new_prime_child(std::string name, unsigned int flags, Case gcase)
{
Concept& prime = this->all_concepts[this->prime_event];
Concept& arg = this->new_concept(flags, {name, gcase});
std::cout << "npc-prime&: " << prime.as_str() << "\n";
std::cout << "npc-prime: " << this->all_concepts[this->prime_event].as_str() << "\n";
link_concepts(prime, arg, gcase);
return arg;
}


When
new_prime_child
is called during the program, it prints:

npc-prime&: 139723003658360      null    [] -e-ps
npc-prime: 0 PRIME null [] -e-ps


None of these types have any special constructors defined. Why does the reference point to garbage while the struct prints perfectly fine on the next line when I index directly into the vector?
>>
what the fuck do you use haskell for? And would CSS/HTML5/Javascript be good for Human Resources?
>>
>>52919637
Your code in nextMonth will be inside the class, it has access to the "month" field, you easily-confused MORON!
>>
>>52919965
I think HR would slap you with a sexual harassment charge if you suggested javascript.
>>
WHY NOT HAVE TWO SEPARATE LOOPS FOR FUCK'S SAKE

YOU'RE DOING TWO SEPARATE TASKS
>>
>>52917024
>>52916755
You are aware that pointers are used in arrays, right?

When you make an array of ints, you're making a sequential segment of memory. Here, try this. Then you take the address of the first element and you store it in variable
int arr[10];
for(size_t i=0; i<10; i++) arr[i]=i;
cout << arr << endl;

cout << arr[0] << endl;
cout << *arr << endl;

cout << arr[1] << endl;
cout << *(arr+1) << endl;

output:
0x28fee8
0
0
1
1


A pointer to an array of pointers is a pretty much translated to "an array of arrays"
>>
>>52919965
>what the fuck do you use haskell for?
being a smug hipster/tranny fagggggggggggggggg

>And would CSS/HTML5/Javascript be good for Human Resources?
just say you have experience, you won't have to prove it
>>
float onePercent = (float)1 / (float)100;
>>
https://www.hackerrank.com/challenges/c-tutorial-functions
how bow dis
#include <iostream>

int largest (int *nums) {
int win = 0;
for (int i=0; i<4; i++)
if (nums[i] > win) win = nums[i];
return win;
}


int main (void) {
int n[4];
scanf("%d %d %d %d", &n[0], &n[1], &n[2], &n[3]);
std::cout << largest(n) << std::endl;
return 0;
}

how i do, and let's see yours so i can git gud
>>
>>52919797
>How? Is it trapped?
yes, the CPU will fault if you stuff random stuff in the upper bits; this is how a virtual address is viewed by the CPU:
http://i.stack.imgur.com/sDyyu.png
bits 48-63 must have the same values as bit 47 or the CPU triggers an exception
>>
Help me out /g/

My boss has just approached me with a project. ( i am not a programmer i an an analyst with some c# and sql)


He wants to digitize a paper process.

Using a tablet ( dont know which one) with an e-form on it that a worker completes. And is then saved on out servers.

The idea is that it can be later pulled up. Or searched using sql.

My question.

What language should i be doing this in.

And what resources should i be looking at.


We cant buy anything it has to be internally developed.
>>
>>52920082
I know /dpt/ will shoot me for this but,
make a web app. It just werks and is cross platform. Add a back end that communicates with the SQL server and sends the response to the client as a JSON.
>>
>>52919693
I would go with std::array, if they had C++11.
#include <iostream>
#include <cassert>

int main(int argc, char** argv) {
size_t a = 0;
size_t b = 0;
std::cin >> a >> b;

assert(a>0 && b>0);
assert(a<=b);

std::string numbers[] =
{"one", "two", "three", "four", "five",
"six", "seven", "eight", "nine"};

for(size_t i=a; i<=b; ++i) {
std::cout << (i <= sizeof(numbers)/sizeof(numbers[0])
? numbers[i-1]
: i%2==0 ? "even" : "odd")
<< std::endl;
}
return 0;
}
>>
>>52920025
so youre saying they could be useful? I'm just looking ahead to the future and kind of figuring out some sort of language that I could use professionally
>>
>>52920022
>pretty much translated
not even close
>>
>>52920082
Write it in Basic and run it under the BBC micro
>>
>>52920082
>>52920108
yep, sounds like a simple .NET or PHP web app
>>
>>52920123
don't use them you faggot, just pad your resume with them
>>
>>52920108
I'm sure he understood about 5 of those words.
>>
>>52920062
What happens if I enter all negative numbers?
Furthermore: Try making a version that can handle an arbitrarily large amount of input.
>>
Im having problems getting ffmpeg to ouput processed files in to the provided folder.It just does the coding then drops out with a error about not finding the folder.
I would appreciate any suggestions
#!/bin/sh
mkdir -p done
for file in *.mkv
do
ffmpeg -i "$file" -c:a copy -vf "subtitles=$file" "done/$file" -threads 12
done
>>
>>52920125
You're right. It's actually an array of pointers. Which is what I said. But the use for it is to make a multidimensional array.
>>
>>52920162
Try reading the problem maybe.
>>
>>52920141
any alternatives that would be useful?
>>
>>52920230
java
C++
C#
>>
>>52920065
Sweet, so for the time being on x86_64 I have some bits at the top to stuff with shit. I asked because I have a few structs that are completely pointer values and boolean bit fields and it would sure be nice to fit the few bits of slop from the bitfields into another variable. The least used one.
>>
>>52920108
this

>>52920082
If it's quick and simple, you could use ASP.NET.

If it's going to be a big project, look at MVC.NET.

If it needs to be a native app on the tablet, you could use Xamarin or Unity, but Xamarin is likely to cost you unless you can fudge a Dreamspark license and hope they never audit you.

These suggestions are all based on the fact that you apparently know a bit of C#.
>>
>>52920238
Awesome, I'll look into it any reason as to why they're good? sorry last question and i'm done being retarded
>>
>>52919641

Some machines are approaching the need for >64 bits of memory. 128 bit RISC-V was originally created as a joke, until the creator met with a group that was already using 54 bits of addressable memory, and growing. X86-64 may only use 48 bits of its addressable memory, but the addresses are still 64 bits, because they need to fit on a word boundary. A pointer for RISC-V may have a similar restriction (I should honestly read the spec at this point, but I'm slightly busy)
>>
>>52920255
they're proper programming languages
statically typed
support multiple programming paradigms (mainly object-oriented though)
have great performance
used for serious applications
>>
>>52920169
you were told already, this thread is not for this.
>>
>>52920255
Those three at wildly popular languages in many different corporations. Java is used basically everywhere. C++ is use for lots of enterprise app dev. C# interops with the whole Microsoft stack like a dream, and since most companies use one of: Active Directory, Exchange, SQL Server, etc, then it's becoming ubiquitous for rapid in-house dev.
>>
>>52920282
and they're popular, widely used in the software industry
>>
>>52916218
this desu
>>
File: 1421151307921.jpg (743 KB, 1920x1200) Image search: [Google]
1421151307921.jpg
743 KB, 1920x1200
Can i get some help /g/eniuses. Im looking to cin a struct member into a struct.
>>
>>52920295
Looking at the last 3 threads,i was never given a response.(looking again just now)
My question is too high of knowledge for the /sqt/. This is a programming thread, i am currently attempting to make this work.
>>
>>52920272
>the need for >64 bits of memory
doubtful; we're talking virtual address space here, ie. per-process; even if you have a machine with let's say 4 PB of physical RAM (which is insane already), you can still have 16 processes each using 256 TB of RAM with just a 48-bit address space. are you saying there's a need for an address space of 16 EB? what application is that? you'll need to provide some citations
>>
>>52920390
Ask in the FFMPEG IRC. This isn't programming related.
>>
>>52920402
>what are supercomputers
>>
>>52920409
>writing bash script
>not programming
>>
>>52920431
bash/PowerShell/cmd/etc are generally not /dpt/
>>
>>52920431
>drawing a stickman is considered painting
>>
>>52920390
>My question is too high of knowledge for the /sqt/
>getting ffmpeg to ouput processed files in to the provided folder
it really isn't

>>52920431
no, it's scripting
>>
>>52920423
obviously something you know little about;
protip: it's not "a" computer with "a" cpu and "a" motherboard where you plug ram sticks
>>
File: hahaha oh wow.jpg (38 KB, 562x437) Image search: [Google]
hahaha oh wow.jpg
38 KB, 562x437
>>52920431
>
#!/bin/sh
mkdir -p done
for file in *.mkv
do
ffmpeg -i "$file" -c:a copy -vf "subtitles=$file" "done/$file" -threads 12
done

>programming
>>
Java;

3 classes, Dog, Kennel, and Info.

Info asks the user for information about a Dog. Info has an array of Kennels. Kennels has a reference to Dog in it. Info calls upon a reference to Dog, and Info asks for information about description, weight, breed, et cetera and stores it into Dog. Info checks if there is any existing Dogs with the same information in Kennels, and then stores it into a new Kennel if there is no other dogs like it.

I have something like this, but the problem is, when I check "if(dog.equals(kennels[i].getDog())) {" or "if(dog.equals(kennels[i].dog)){" or anything like this, it always is true. I went through the debugger and my program is referring to the same Dog for every reference to Dog, even though I have made new Dog references with different names (kennelDog, infoDog), etc. So, every single time Dog is changed, it also changes the information about the existing Dogs in each Kennel. Why is this happening? What do I need to do to make the reference to Dog completely separate and unique to the Kennel?
>>
>>52920525
>homework
>>>/stackoverflow/
>>
>>52920423
What are they, anon? And how much address space do they need?
>>
>>52920525
Dog newDog = new Dog();
>>
>>52920544

no
>>
>>52920550

I call on a new Dog in both Kennel and Info

I debugged it and set breakpoints on anytime either Dog is modified and they have the same ID and stop twice for each edit to Dog
>>
>>52920570
post code you giant dickbutt
>>
>>52920423
>discussion about virtual address space limitations
>"what is" meme
sounds like you're out of your element m8
>>
>>52920431
>script
>programming
anon...
>>
have any of you come to terms with the fact that you will almost certainly never have a non-pleb gf
>>
>>52919018
Why not use a flat array?
>>
>>52920657
Yeah.

Dated for many years, had one relationship that lasted 5.

Sure, I want kids someday, but the general experience of having a significant other is more hassle than benefit in my experience.

Going to wait until I'm about 30 years old. Already making good money now, will likely be making six figures by that age.
>>
>>52920684
are you really asking this to a guy that can't write code worth a shit?
>>
>>52920702
>I want kids someday
why?
>>
>>52920657
>not asexual master race
>being this shit at programming
>>
>>52920712
he can probably write code p well he's just trying to piss people off
>>
>>52920723
to pass on your genes obviously you dumb cuck
>>
>>52920738
unlikely; the odds are he's incompetent
>>
>>52920755
again, why? what good does that do for you?
>>
Installing chormixium on an fckng old notebook... Oh man, it's lagging like a shitsung....
>>
>>52920730
how can you be asexual? do you have no libido? do you masturbate?
>>
>>52920583

Relevant bits from the Kennel class

Dog dog = new Dog();

public Kennel(){

}

public Kennel(Dog dog, String description){
this.dog = dog;
this.description = description;
}

public void setDog(Dog dog){
this.dog = dog;
}

public void setDog(int height, int weight){
height = dog.getHeight();
weight = dog.getWeight();
}


Relevant bits from the Info class

Dog dog = new Dog(); // I've tried changing the names of either but it doesn't effect it
private int numDog = 0;
private Event[] events = new Event[10];
public void addDog(){
System.out.println("Enter dog description: ");
String description = scanString.nextLine();
System.out.println("Enter dog height: ");
int height = scanInteger.nextInt();
dog.setHeight(height);
System.out.println("Enter dog weight: ");
int weight= scanInteger.nextInt();
dog.setWeight(weight);
for (int i = 0; i < kennels.length; i++) {
if (dog.equals(kennels[i].getDog())){
System.out.println("Already a dog like this in the kennel");
break;
}
}
numDog++;
kennels[numDog] = new Kennel(dog, description);
kennels[numDog].setDog(dog);

yes I know this is trash
>>
>>52920806
>masturbate
ewwww... gross, anon!
>>
>>52920776
It would give me a sense of satisfaction on my deathbed that I'm leaving something behind, potentially generations of somethings.

Pseudoimmortality and all that.
>>
>>52920755
You're a conscious being, you know, not some amoeba. You don't have to throw away your life just because some biological impulses.
>>
>>52920827
>public void setDog(Dog dog){
> this.dog = dog;
>}
barf; so many useless keystrokes
>>
>>52920855
kill yourself fag
>>
>>52920834
ah, you're delusional; carry on
>>
>>52920423
0/10.

Even the world's largest supercomputers aren't anywhere close to having 16 Exabytes of RAM. The largest I can find are the IBM Sequoia and NCSA Blue Waters, both at 1.5 PB (that's 10,000x less).

And even if a supercomputer had that much memory, there's no benefit to a CPU being able to directly address the entire memory pool. You can't attach 16 EB to a single CPU (you literally can't fit that much RAM within the maximum length of a front-side bus), and access to other CPUs' memory banks is done via message passing, not direct access.
>>
>>52920868
found the "enterprise" cuck
>>
>>52920855

im so sorry
i just started please forgive me
>>
>>52920827
put the Dog dog = new Dog() inside the addDog method because the way you have it now, you have just one dog that you're changing into the new dog
>>
>>52920884
>what are secret government projects
>inb4idisappear
>>
When making a C++ class. Do you think it'll be better to copy pointers or copy whole arrays?

For example
MyClass operator=(const MyClass &rhs)
{
array = rhs.array;
}

Or
MyClass operator=(const MyClass &rhs)
{
for(size_t i=0; i<rhs.sz; i++)
array[i] = rhs.array[i];
}


I think I should add both ways. But it seems kind of pointless when you can just do
 MyClass lhs = &rhs 

and it does the same thing.
>>
>>52920926
> to copy pointers
Who's the owner? Who will delete the data, and how will the other pointer know about it?
>>
>>52920876
>delusional
Can you explain what part of what I said indicates that I'm having any sort of delusion?

There is a chance for your genetics to remain for the rest of human history.

Whether or not that means anything to you is subjective.
>>
>>52920926
I think the second one is better. That's what I expect from a copy constructor.
>>
>>52920926
I'd deep copy the array. The first is error prone.
>>
>>52920902

Ah, alright

If I had another method, like, lets say to edit the Dog in addDog, how would I call on it? addDog.dog?
>>
>>52921016
>remain for the rest of human history
>subjective
that's where the delusion comes in
>>
>>52920992
Well. Right now I'm just creating a basic node system. Array just holds "MyClass" elements. But I hope in the future to make it as advanced as I can get it so I can use it for anything. I'll probably just make everything virtual so I can overwrite it when I'm using it for something else.

>>52921030
>>52921031
Yeah. I thought so too. But I've seen many times where some programs implemented it with pointers.
>>
>>52920834
>pseudoimmortality
actually, you'll be just dead
>>52921016
>your genetics to remain for the rest of human history
you can't know that, you're dead; either way, remaining or not, doesn't affect you, you're dead
sounds like "delusion" is a proper description for your affliction
>>
>>52921138
Sometime just copying the reference could be the wanted action. Just write in the documentation what it does and that the memory shouldn't be freed twice if only the pointer is copied.
>>
>>52921092
addDog will make a new Dog every time so there is no addDog.dog

you're storing each new Dog in kennels[numDog] so get them from there or store them somewhere else
>>
File: Boogiepop.Series.full.1091509.jpg (164 KB, 1920x1200) Image search: [Google]
Boogiepop.Series.full.1091509.jpg
164 KB, 1920x1200
Mutator method or no?
>>
>>52920684
Flat dynamically allocated arrays require unsightly pointer arithmetic hacks to use them correctly.
My method lets you use array subscript just like stack allocated arrays.

by the way, freeing it is just as easy
void destroy_cube(cube_t *ptr)
{
unsigned i, j;
for (i = 0; i < ptr->size.x; i++)
for (j = 0; j < ptr->size.y; j++)
free(ptr->cube[i][j]);
for (i = 0; i < ptr->size.x; i++)
free(ptr->cube[i]);
free(ptr->cube);
free(ptr);
}
>>
>>52921178
assignment or no?
>>
>>52921160
>>52921103
some people value things other than themselves. there isn't much else you can do anyway. like what... watch anime? anime fucking sucks. and drugs are bad m'kay
>>
>>52921160
>you can't know that
You know that there is a chance while you still live. It would be something to hang on to until the moment you cease to exist.

If affects you while you're still alive.

Is this really that difficult to understand?

I'm an atheist, and I'm quite aware that after death is nothingness. I just want to maximize positive emotions while I'm alive.
>>
>>52921197
>pointer arithmetic hacks
you're incompetent if you need "hacks"
>freeing it is just as easy
sure, just as easy as "free(the_whole_thing);"
>>
>>52921178
If you need it for performance reasons then why the hell not?
Thread replies: 255
Thread images: 23

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.