[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: 31
File: daily programming thread2.webm (2 MB, 600x338) Image search: [Google]
daily programming thread2.webm
2 MB, 600x338
old thread: >>52566734

What are you working on, /g/?
>>
First for nimfriends
>>
In C, how many levels of indirection is too much?
Note that you will be graded and judged based on your answer, so choose wisely.
>>
>>52572109
You should never even use pointers ideally.
>>
>>52572064
10 posts early, again
great job
>>
File: 1426680121535.png (9 KB, 647x53) Image search: [Google]
1426680121535.png
9 KB, 647x53
I'm designing the instruction encoding for my VM, it is RISC based with fixed instruction size which also must be word aligned (32 bit).
The problem is that I have 2 bytes wasted, I could fill one of them with a flags byte, but what should I do with the other?

Beware that I'm not a computer scientist, I've never taken any computer architecture class and I'm doing this out of my own interest.

>>52572109
2
>>
>>52572109
i like to abuse structs and treat them like objects complete with vtables, so I can easily reach 6+ levels of indirection.
More if I'm creating arrays of arrays of structs.
>>
>>52572109
Even 0 levels is too much in C because using C is too much and thus only not using C is less than too much.
>>
>>52572125
Add a barrel shifter (to help construct immediates). Bitches love barrel shifters.
>>
>>52572122
Your life must be pretty difficult if you get bothered by things as small as this.
>>
>>52572064
Fuck off earlyposting animefag. You're not welcome here.
>>
>>52572208
No one is welcome here, ideally.
>>
>>52572109
>In C, how many levels of indirection is too much?

8 star or you aren't even using C to its full potential.
>>
>>52572109
there is no such thing as too much indirection
>>
>>52572064
Threadly reminder you don't need anything other than C and Lua.
>>
>>52572275
If your time is worthless*
>>
>>52572275
Threadly reminder you don't need anything other than ocaml. Why break your neck with C, and your soul with Lua, when you could just use ocaml?
>>
>>52572208
>>52572217
That means we'll need to join the Contributor Convenant (http://contributor-covenant.org/) because now I don't feel safe and accepted to post here anymore.
>>
>>52572109

In theory, there is no such thing. Some tasks call for tree data structures, which allow for arbitrary amounts of indirection.

If you're referring to how many stars should be too much for a pointer type, three star is the maximum I've ever needed. This was for a program to output both an array of strings (taken in as a char***) and return a number of arguments. The results of this function would be fed into argvp.
>>
>>52572380
Will this guy ever get over himself?
>>
>>52572365
I feel violated by you even linking that.
>>
so if this was my code in bash
read -p "value: " val1
echo $val1
exit

is whatever I type as val1 stored anywhere? i.e in bash history if so how would I go about stopping this?
>>
File: 1429604510048.png (31 KB, 1035x150) Image search: [Google]
1429604510048.png
31 KB, 1035x150
>>52572125
Okay, how's this?
>>
>>52572275
I endorse this, because I like small things.
<3
>>
>>52572390

Who?
>>
>>52572365
>http://contributor-covenant.org/
ree
>>
Reminder that if you can't print out a diamond, you obviously shouldn't be a programmer.
>>
>>52572414
What if it was
[cond] [opcode] [flags] [reg1] [reg2 / const]?

That way every single instruction can be executed (or not) based on the result of whatever comparison instruction last set the conditional state (eq, ne, gt, lt, gte, lte), instead of just jumps.
>>
What are you guys gonna do today (non programming related things)
>>
>>52572498
Fap to anime
>>
>>52572408
No.
>>
>>52572365

Anon, it is literally not possible to punch someone through the Internet, despite how much many of us wish it was. If you feel unsafe here, you need therapy.

>>52572125

Consider looking at other RISC architectures for how they organize their opcode spaces before designing your own. I recommend looking at MIPS.
>>
>>52572491
Interesting, can you give a situation where that would be useful/convenient/more efficient as opposed to jumps?
>>
>>52572488
i know how I would do it, i'm just too lazy to write it out and debug it.
does that count?
>>
I finished the python course in code academy and I've taken a university course in C++
what kind of program should I make
>>
>>52572498
>
>>
File: small-GnashGnu.png (33 KB, 180x188) Image search: [Google]
small-GnashGnu.png
33 KB, 180x188
>>52572275
You mean C and Scheme.
>>
>>52572531
Print out a diamond.
>>
>>52572522
>Anon, it is literally not possible to punch someone through the Internet

With my invention it will be possible to shoot people over the internet. All you need is an arduino, stepper motor, some string, and a Winchester Model 100 or comparable semi-automatic rifle.
>>
>>52572525
I don't think so, man. I'm going to have to revoke your certification.
>>
>>52572560

May I recommend a SBC that is actually capable of connecting to the internet without an extension? Arduino isn't really for net connected shit.
>>
>>52572523
ARM.
toupper:
@ skip prolog
cmp r0, 'a'
cmpge r0, 'z'
subslt r0, 32 @ 'a'-'A'
>>
>>52572554
I'd like something that at least seems neat.
>>
>>52572609
Cool, will consider it.
>>

using namespace std;

struct Heap {
string name;
Heap *left = nullptr;
Heap *right = nullptr;
};


Heap *heapFromArray(string *input, int length);


Heap *heapFromArray(string *input, int length) {

Heap *dynArray;
dynArray = new Heap[length];

for (int i = 0; i<length; i++){
dynArray[i].name = input[i];

//WHAT THE FUCK GOES HERE??//
dynArray->left= &dynArray; //this is obv wrong
dynArray->right = &dynArray; //this too

}

for (int i = 0; i<length; i++){
cout << dynArray[i].name <<endl;
}

return dynArray;

}

int main() {
// input for testing
string maBands[] = {"Led Zeppelin", "The Beatles", "Pink Floyd", "Queen", "Metallica","ACDC", "Rolling Stones", "Guns N' Roses", "Nirvana", "The Who", "Linkin Park", "Green Day", "Black Sabbath", "RHCP"};
int numBands = 14;

// creat heap
Heap *heapOfBands = heapFromArray(maBands, numBands);


So I'm picking up C++, the code is simple enough to follow. I'm organizing the string in a dynamic array of type struct. How do i go about linking the left and right pointers to correct location in the array?
>>
>>52572602

You can recommend whatever you'd like. I've actually spent less time with Arduino and similar devices than I'd like to admit.

I should probably start doing some experimenting with them.
>>
>>52572658

I've used an Arduino for only one project -- a simple binary counter. I'm unsure if what the fuck to make with it. I don't have much in terms of parts except for the starter kit with an Arduino uno.
>>
>>52572653
I don't understand what you're trying to do.
>>
>>52572707

to be honest, I just like software better. I don't dislike hardware, but.. you know.. I just live and breathe software.

no homo.

>inb4 smug EE majors start shitposting
>>
>>52572762

Kinda same, although I do like writing software that interfaces with hardware. Low level driver code actually seems like a fun job to me.
>>
File: regards sad from.png (12 KB, 640x560) Image search: [Google]
regards sad from.png
12 KB, 640x560
>>52572791

I don't see myself doing that, but I wouldn't mind if it paid the bills. If I got taken in as some hardware wizards protege, I'd probably learn to love it.

>tfw no greybeard to teach me computer magic
>>
that was fun

http://pastebin.com/8J2CdamN
>>
>>52572753
Im sorting the string maBands[] into a heap (binary tree)
dynArray[i].name = input[i]; //saves each string into struct


Now I need to link

Heap *left = nullptr;
Heap *right = nullptr;

Now I want to point these to the correct structure in the array, but I'm stuck there.

Left should point to 2*i+1 and Right should point to 2*i+2. ( i is the current array index, ex. dynArray[i])
>>
File: D_Programming_Language_logo.png (232 KB, 1000x758) Image search: [Google]
D_Programming_Language_logo.png
232 KB, 1000x758
potential new D logo lads
https://i.imgur.com/r9WPvEX.png

current one is the image
>>
>>52572920
Wow, it's fucking nothing.
>>
>>52572879

Looks like your implementation of loops isn't quite right. The only reason it sticks right out at me is because I made the same mistake when I first wrote my BF interpreter. You need to handle nested loops.
>>
>>52572933
>gets rid of all of the weird shitty gloss / shine effects
I like it personally
>>
There should be a name for that pivotal moment when you discover the power of abstraction and code reuse.

It's repeated over and over in beginner textbooks, but you don't really get it until later.
>>
>>52572920
Really liking the bottom left
>>
>>52572884
>Left should point to 2*i+1 and Right should point to 2*i+2.
Well if that's what you need to do then do that. What's your issue?
>>
>>52572509
What anime?
>>
>>52572884
dynArray[i].name = input[i];
dynArray[i].left= &dynArray[2*i+1];
dynArray[i].right = &dynArray[2*i+2];
>>
>>52572625
Print out a diamond made of your name.
>>
>>52572939
what do you mean? Like where if you put in a ] and not an [ having it throw an error rather than breaking? Or just using them in general like

for (char c : input) {
for (int i = 0; i < accepted.length; i++) {
if (c == accepted[i]) {
chars.add(c);
break;
}
}
}
>>
prove to me you aren't a charlatan
>>
>>52573057

It looks like when you hit a [ or ], you start searching to find the matching one, but you aren't keeping track of other ones you pass over..

think of it like this:

[....[..]...]


If you are at the last position there, and you need to loop back to the first, you can't simply search the string backwards until you hit the '[' char, because that will drop you into the loop inside the one you're trying to get to the head of.

Keep a counter where, say, '[' increases it, and ']' decreases it, then break when it's equal to zero. This will place the PC at the appropriate instruction.
>>
>>52573057
He means you aren't handling nested loops. you are expecting only one level of looping. You should be using a stack. If you've done a reverse polish calculator the implementation should be pretty similar.
>>
>>52573135
>You should be using a stack.

A counter has the same effect. When I initially wrote mine, I used a stack, but then I compacted the code and just used a counter.
>>
>>52573150
>he didn't write a recursive decent parser
>backtracking
lol
>>
>>52573214
>all that shit by you
>for fucking brainfuck

no
>>
>>52573227
Shit's probably more compact then one that's not.
>>
File: Walruse.png (27 KB, 155x145) Image search: [Google]
Walruse.png
27 KB, 155x145
>>52572064
I have to create a program that simulates carbon emissions.
>>
>>52573135
>>52573099
oh, yeah that's an easy fix
just number your brackets as you come across them and then go to the most recent one in the code

like

[.....[...].............]
1....2..<2.........<1(or whatever the previous one is)

yeah I caught the skipping the [] when it is zero right after I posted it, I just didn't read the rules all the way through the first time
>>
>>52573275
>oh, yeah that's an easy fix

It is, it's just an easy mistake to make. Like I said, I noticed it right away having made it myself.
>>
File: Window.png (401 KB, 742x1001) Image search: [Google]
Window.png
401 KB, 742x1001
What is the best way to scale an image along with the window in OpenGL without changing the aspect ratio?
For instance, I have a quad that covers the entire screen corner-to-corner, and I have an image drawn to it, so it's kind of like a shitty image viewer.
But when I change the window size the image does not scale right, how can I make this better?
>>
File: Window.png (401 KB, 744x1003) Image search: [Google]
Window.png
401 KB, 744x1003
Did my post get deleted? I don't see it anymore.
Reposting just in case.

What is the best way to scale an image along with the window in OpenGL without changing the aspect ratio?
For instance, I have a quad that covers the entire screen corner-to-corner, and I have an image drawn to it, so it's kind of like a shitty image viewer.
But when I change the window size the image does not scale right, how can I make this better?
>>
>>52573452

scale one direction, then use the ratio of width/height to scale the other.
>>
>>52573297
>>52573452
Whoops.
>>
>tfw getting this error

public Class Foo{
Bar bar = new Bar("dicks");
bar.run();
}

Class Bar{
String str;
public Bar(String str) {
this.str = str;
}
public void run()
{
System.out.println("output: " + str);
}
}

output
Output: null


Obviously I'm not programming something this simple but this is in essence what's happening. What's worse is that when I have a breakpoint at public Bar(String str), it says it's null there too.
How the fuck is that even possible? I haven't changed any of my code and it used to work but now it doesn't.
>>
>>52573460
Should I scale with the shader or the viewPort?
I was thinking of doing bicubic interpolation.
What would this look like in C?
>>
File: dfdisk_view.png (3 KB, 640x300) Image search: [Google]
dfdisk_view.png
3 KB, 640x300
It now properly shows (most) forms of partition on a disk now.
>>
>>52573495

Doesn't openGL already have something to draw scaled images?
>>
>>52573460
hmm not sure I agree with this

I think you can directly scale your shit in opengl, what i would do is a vertical and horizontal check of your window space, get the one your image would collide with first after growing, and find the ratio of that width to the width of your image. Then scale your image up that ratio.

Might be wrong about the scale thing but iirc there was an Image type and you can use image.draw(y,z,5.1f,[scale factor here])
>>
>>52573510
I don't think so.
>>
>>52573297
float scale = wwin < hwin ? wwin / hwin : hwin / wwin;

float wscaled = wimg * scale;
float hscaled = himg * scale;
float x = wwin / 2 - wscaled / 2;
float y = hwin / 2 - hscaled / 2;

/* make quad with x, y, wscaled, hscaled */


Something like this?
>>
>>52573518
ok maybe I was wrong actually

you can do it with slick2d(definitely) and jwjgl (it's more complicated). For jwjgl you draw an image on something as a texture, so you change the dimensions of the polygon you're drawing the image on
>>
File: Screenshot 2016-01-22 22.47.20.png (20 KB, 978x172) Image search: [Google]
Screenshot 2016-01-22 22.47.20.png
20 KB, 978x172
Like actually how the fuck is this possible
The constructor just... isn't getting the value.
>>
>>52573502
Can anybody explain to me why this is return 0??

uint32_t disk_usage = (part_size / disk_sizemb) * 100;


I've tried using ceil as well to no avail..
>>
>>52573660
NodeMaster isn't initialized
>>
>>52573679
What do you mean?
JobHandle jobHandle;
NodeMaster nodeMaster;

public PrimaryClient(NodeMaster nodeMaster, JobHandle jobHandle) {
this.jobHandle = jobHandle;
this.nodeMaster = nodeMaster;
}
>>
>>52573692
  NodeMaster nodeMaster = new nodeMaster(Params)
>>
>>52573696
NodeMaster*
>>
>>52573696
But anon. The constructor is taking an instance of NodeMaster that was properly instantiated (see the top half of the screenshot, it's not null), but when it's passed to the constructor it becomes null.
>>
>>52573710
NodeMaster nodeMaster


This isn't proper initialization. nodeMaster is null here.
>>
>>52573719
Yes. Nodemaster is null there.
But look at where the breakpoint is. The value caught with the constructor is null. It shouldn't be. It should be whatever value was passed to it.
>>
File: life_puffer2s.webm (689 KB, 1920x1080) Image search: [Google]
life_puffer2s.webm
689 KB, 1920x1080
I did Game of Life running in a console, board wraps at top and sides. I wanted to learn bit operations so the board is an array of integers and each bit represents a cell.
>>
>>52573660
Is jobHandle null too?
>>
>>52573746
Yes. I have no idea why.
>>
File: ss+(2016-01-22+at+07.58.30).jpg (251 KB, 1195x723) Image search: [Google]
ss+(2016-01-22+at+07.58.30).jpg
251 KB, 1195x723
I want to get started writing a program, not all the way a game but just a program. I want to make a helper program that can run in the background or sit in the system tray and wait for certain key presses to be done while the game is open, then execute some code. Would it be possible to do this and make the program be more than just a command line? Lets say have a user interface with buttons and whatnot? I would like to do it in C++ if possible. Any ideas?

Image is what my idea is what my kinda idea is like (not exactly this, but of the same topic, an offline guide program or macro holder type program with buttons and shit)
>>
>>52572365
>now I don't feel safe and accepted to post here anymore.
https://www.youtube.com/watch?v=L9_jp2Uwqts
>>
>>52572854

>tfw a few of my professors are literal greybeard wizards.
>One of them wrote software that is part of the GNU project.
>The other has memorized network stacks to insane levels of detail.
>At least two or thee professors have worked with the US government in the past. One for the DoD, one for Lawrence Livermore National Laboratory, and one I think mentioned working with the NSA.
>>
>>52573756

>I want to make a helper program that can run in the background or sit in the system tray and wait for certain key presses to be done while the game is open

What OS, Windows?
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646301%28v=vs.85%29.aspx

GetKeyState is used to determine whether or not certain inputs are being used or not. If you want some example code, I've actually used it in a gem for MRuby:
https://github.com/expeditiousRubyist/mruby-autoclick/blob/master/src/mruby-autoclick.c

As for giving it a GUI, that is perfectly possible, although if the purpose of the program is to run in the background, why not make it a CLI program?
>>
>>52573666
Stick to Python, please.
>>
File: tiles.png (651 KB, 1148x748) Image search: [Google]
tiles.png
651 KB, 1148x748
changed how the catalog looks a bit
>>
>>52573865
to add on to this I know you can also automate literally every macro amd mouse movement imaginable using java.awt.robot, I bet c++ would have something similar
>>
>>52573493
>that indentation
McFucking kill yourself
>>
>>52573935
>expecting indentation to be good when it's pseudo-code typed directly into 4chan which has absolutely no formatting tools
?
>>
OOP is pretty comfy desu.
unsigned search_subgrid(grid_t *pattern, grid_t *subpattern, point_t from)
{
unsigned matches = 0;
unsigned k, l;
for (k = 0; k < subpattern->size.x; k++)
{
for (l = 0; l < subpattern->size.y; l++)
{
if (pattern->grid[from.x + k][from.y + l] == subpattern->grid[k][l])
matches++;
}
}
return matches;
}
>>
>>52573777
But were they ever highly respected trip fags?
>>
>>52573879
Is this the one that starts with a 'V'? Got a link to the source?
>>
>>52573777
>One of them wrote software that is part of the GNU project.

Is that supposed to be impressive?
>>
>>52573955
https://github.com/vaccineapp/vaccine
>>
File: 1450568178435.jpg (835 KB, 986x1000) Image search: [Google]
1450568178435.jpg
835 KB, 986x1000
rate my rust program /dpt/
use std::io;

fn main() {
print_info();

let mut choice = String::new();
io::stdin().read_line(&mut choice)
.ok()
.expect("Failed to read line");
let choice: u8 = choice.trim().parse()
.expect("Failed to convert to number");

println!("Enter temperature to be converted:");
let mut temp = String::new();
io::stdin().read_line(&mut temp)
.ok()
.expect("Failed to read line");
let temp: f64 = temp.trim().parse()
.expect("Failed to convert to number");

println!("{:.2}", match choice {
1 /*f->c*/=> (temp - 32.0) * (5.0 / 9.0),
2 /*c->f*/=> temp * (9.0 / 5.0) + 32.0,
3 /*k->f*/=> (temp - 32.0) / 1.8 + 273.15,
4 /*f->k*/=> (temp - 273.15) * 1.8 + 32.0,
5 /*k->c*/=> temp - 273.15,
6 /*c->k*/=> temp + 273.15,
_ => { 0.0}
});
}
>>
>>52573974
10/10

Stop doing shitty K&R exercises though
>>
>>52573993
the k&r exercise didn't have kelvin! :^)
i am doing easy problems because i am both a beginner to programming and rust
>>
>>52573974
Don't fall for the rust meme anon, just be smart and do it in C
>>
>>52574015
>the future of systems programming is a meme
>>
>>52573972
>https://github.com/vaccineapp/vaccine
Thanks
>>
>>52573974
Are there really people who hate C syntax so much they want to be different for different's sake?

There's a reason most languages look like C, the syntax is great and easy for a programmer to understand, even if they don't know C.
>>
>>52573493
>>52573660
Anons, does anyone know what might be causing this?
I just added another constructor, an integer, and it went through just fine.
>>
>>52574036
the syntax is pretty much exactly like c. certain things are different because of weird variable bindings and type inference
>>
>>52574023
Just like and D and C++ were the future right anon?
>>
>>52574073
I'd say C++ cemented itself pretty well, being that it's the choice for all non-embedded performance critical code
>>
Added an open in browser button
>>
>>52573892

There is nothing in the C++ standard library for automating mouse and keyboard. However, depending on the platform, there will be system calls for doing exactly that. On Windows, the function is called SendInput(). On Linux... I would look into how the xdotool program works... or just invoke it directly via a bash script.
>>
>>52573865
I like the idea of a program to be opened up and have settings changed at a glance, not something just I would use, but potentally others. Also wanted to includ some other tools in it. How hard would implementing a GUI be? Any special libraries to reccomend?
>>
File: Can't wake up.png (241 KB, 1716x937) Image search: [Google]
Can't wake up.png
241 KB, 1716x937
>trying to add overflow detection
>signed type addition/subtraction has a carry-out in its addition and subtraction
>can't access it
>have to use retarded hacks unless I want to write the code for adding/subtracting myself
>change my variables to signals so that I could watch them more easily in the simulator
>addition spontaneously stops working

Why can VHDL be so retarded sometimes
>>
>>52572118
>never use pointers
>in C
>>
>>52574145
Sup newbie
>>
>>52572118
>what is performance
>>
>>52574168
Why use C if you're never gonna use pointers?
>>
>>52574182
I forgot that was the only benefit of using C
>>
>>52574135

Qt can be used for GUI stuff on any platform, although it's a bit of a heavyweight. Other options are GTK+, WxWidgets, and FLTK. Or you could just use the OS' native shit if you're a masochist (or need the program to be tiny as shit).
>>
>>52574195
It's one of the bigger ones
>>
>>52574177
If you need to pass a pointer you've already lost out somewhere
>>
I don't know desu senpai
>>
>>52574195

Avoidance of pointers in C is neither idiomatic, nor very performant, and it heavily restricts what one is actually capable of doing, now that all string and array operations are permanently off the table.
>>
>>52574252
arrays aren't pointers so you can use them
idk if passing an array to a function counts because of the implicit pointer conversion
>>
>>52574196
Yea iv been feeling like im not doing much with computer science evne though its my major, and my resume is pretty lacking, so I feel as though i Should stop wasting my time and make stuff that i need or that others would like! Thank you for showing me this. Getting other foreground windows and minimizing to the system tray would all be done seperatly with the windows API correcT?
>>
>>52574252
Valuable C work doesn't contain strings. Don't need pointers to access arrays.
>>
File: these are the end times.gif (347 KB, 813x508) Image search: [Google]
these are the end times.gif
347 KB, 813x508
>fixed the weird issue with a weird solution (for some reason the variables couldn't share the same variable name, even though that shouldn't have been a problem
>Now, the constructor is hit but the inside of the constructor is never executed
what the fuck is going on
>>
>>52574301
>PrimaryClient
>new ClientJobManager

Are you sure this isn't the problem?
>>
>>52574224

Anon, any data type bigger than a register should always be passed by pointer to avoid unnecessary copying of data structures. If you don't want your structure to be mutable, make the pointer const.

>>52574264

A function with the signature
void foo(int ary[], size_t len);


Is 100% identical to a function with the signature
void foo(int *ary, size_t len);


Arrays are nothing but syntactic sugar for a block of contiguous memory on the stack. Any function which accepts one as an argument is always passing one by pointer without exception. Furthermore, an array subscript is merely syntactic sugar for a pointer dereference. ary[i] == *(ary + i).

All programs are made of pointers without exception. If your program uses memory, it uses pointers. High level languages tend to abstract this away from the programmer. Consequently, many of these high level languages are written in C. C does not abstract these away from the programmer; it expects the programmer to know and understand what pointers are, what memory is, and how to use it.

>>52574296

Qt may be able to do both of those things. Not sure. But honestly I wouldn't mix Qt and Win32 API GUI stuff. If one's going to dip down that low, why the hell not go all the way?
>>
>>52574301
>Declaring things under the constructor

*vomits*
>>
>>52574318
I just had that breakpointed because for some reason it was getting passed null values, which I figured I had remedied. I don't see why instantiating another class would result in the constructor being skipped entirely.
>>
>>52574320
I don't normally do that, anon. my code structure is really fucked up right now because I'm attempting to figure out what the fuck is going on, the kinds of issues I'm running into here are counterintuitive as all getout.
>>
>>52574300

>Valuable C work doesn't contain strings
All non-dead programs do I/O. Nearly all I/O involves strings. Most valuable C work does involve string manipulation, among other things.

Accessing arrays does not necessarily require explicit usage of pointers, but any function which manipulates them does. Moreover, without the use of pointers, one is limited to static, stack-allocated arrays. These are good for small buffers, but not good for large amounts of memory, or when one needs to resize memory at runtime (i.e. a vector).
>>
>>52574264
>arrays aren't pointers
>idk
these are the people arguing against C? jesus
>>
>>52574301
I'm not sure what the problem here is. The constructor isn't being used so you never hit a breakpoint in it.
>>
>>52574319
Can QT do all of the minimization to the tray and still have hotkeys that can work outside of the program being the current windo?
>>
>>52574319
>>52574384
I'm not sure what >>52572118 classifies as using pointers. Is printf("Hello world"); allowed? Is passing an array to a function allowed, as long as you don't write a * ?
>>
function toTimestamp(value) {
let parts = value.split(':').reverse();
let seconds = parseFloat(parts[0]) || 0;
let minutes = parseFloat(parts[1]) || 0;
let hours = parseFloat(parts[2]) || 0;

return Math.floor(
seconds * 1000 +
minutes * 60000 +
hours * 3600000
);
}

function fromTimestamp(value) {
let hours = Math.floor(value / 3600000);
let minutes = Math.floor(value / 60000) % 60;
let seconds = (value / 1000) % 1000;

console.log(hours, minutes, seconds);
}


> fromTimestamp(toTimestamp('1:23:52.4532653'))
1 23 32.45300000000043


Why am I getting a value of 32 for seconds instead of 52?
>>
>>52574417
>let seconds = (value / 1000) % 1000;
>% 1000

there's only 60 seconds, so modulo 60.
>>
>>52574409
No, you sick fuck.
>>
>>52574409

>Is printf("Hello world"); allowed?

>int printf(const char *format, ...);
>const char* format
>const char*
>*

Not allowed. Even a string literal is a pointer to a block of memory in .rodata or .data
>>
>>52574482
Thanks, I thought I was still working with milliseconds for some reason.
>>
>>52574393
The constructor is being used though.
>>
>>52573666
Integer division?
>>
>>52573666
well what are the values of part_size and disk_sizemb?
>>
Stop replying to the the anti-pointer troll.
>>
>>52573879
Please don't upscale images.
Keep the frame the same size but keep the images at original scale please.
Not like I'm ever going to use this GTK3 shit anyway.
>>
>>52574490
Obviously the topic was writing pointers yourself and not "using code that uses a pointer"
>>
>>52574607
Stop trying to avoid pointers, you dumb shit.
>>
>>52574631
Your code gets worse with each level of indirection.
>>
>>52574607
This is backpedaling. Code that uses a pointer only further shows why pointers are useful in the first place.
>>
>>52573974
A bit rusty.
>>
>>52574640
I'm pretty sure you're just not good enough to understand more than 1 level of indirection, so you actually believe this
>>
>>52574640
You can't implement most data structures without using pointers that go as deep as your input will allow.
>>
>>52574641
It was the original argument. You can be sure that if the code was made better they would have avoided pointers.

>>52574650
http://c2.com/cgi/wiki?ThreeStarProgrammer Found your bio kid
>>
>>52574045
>the syntax is pretty much exactly like c
>
println!("{:.2}", match choice {
1 /*f->c*/=> (temp - 32.0) * (5.0 / 9.0),
2 /*c->f*/=> temp * (9.0 / 5.0) + 32.0,
3 /*k->f*/=> (temp - 32.0) / 1.8 + 273.15,
4 /*f->k*/=> (temp - 273.15) * 1.8 + 32.0,
5 /*k->c*/=> temp - 273.15,
6 /*c->k*/=> temp + 273.15,
_ => { 0.0}
});

Okay m8.
>>
I've seen some shit yesterday.
I was helping a friend of mine reading homeworks of master's degree students in cryptography. The hw was to implement data encryption standard(DES). There were some good implementations, some didn't work, some forgot some stuff etc. But everyone did the s-boxes and permutation tables the same way. They put the values in an array or something then used them in s and p-boxes.
Except this one fuck who wrote all of them by hand. Like (pardon my half assed psdcode)
if v[0] = 0 then v_after_p[0] = 3
if v[0] = 1 then v_after_p[0] = 9
etc.
The usual implementation took ~300 lines. This fuck wrote 4K lines. The sad thing is, it doesn't give the correct encryption. The sadder thing is, we later found out that he was a cs major.
>>
>>52574657
>You can be sure that if the code was made better they would have avoided pointers.
If you avoided pointers, your code would not have the functionality you desire in most cases.
>>
>>52574658
float value;
switch (choice) {
case 1:
value = (temp - 32.0) * (5.0 / 9.0);
break;
...
default:
value = 0.0;
}
printf("%.2f", value);


The biggest difference is that switch isn't an expression in C.
>>
>>52574657

How would you print a string without knowing where the string is in memory?
>>
>>52574688
You already have the location in memory by name without your own *
>>
>>52572118
hay anon
unsigned i, j; /* 3D CUBE */ 
unsigned char ***ptr = malloc(sizeof(unsigned char **) * a);
for (i = 0; i < a; i++)
ptr[i] = malloc(sizeof(unsigned char *) * b);
for (i = 0; i < a; i++)
for (j = 0; j < b; j++)
ptr[i][j] = malloc(sizeof(unsigned char) * c);
>>
>>52574708
>not using a flat array

Enjoy your cache misses faggot.
>>
>>52574712
>wasting time looking for uninterrupted memory blocks
enjoy your performance, faggot
>>
>>52574699
What are you talking about? You HAVE to use * to store a string.
>>
>>52574708
>>52574712
>>52574715
>Not using a contiguous array of well designed structs
Enjoy your cache misses, performance and code clarity.
>>
>>52574720
No you don't. You can just view it as an array.
>>
>>52574699
that's how pointers work you dumbfuck, using * dereferences, so you don't want to write it when using printf

>>52574729
an array IS a pointer
>>
>>52574720
char str[64];
>>
>>52574736
You don't need to use *. Read the fucking thread, dipshit.
>>
>>52574715
>not allocating a large block at startup and using a custom memory manager

Pleb.
>>
>>52574740
I just said you're not even supposed to use * for printf you dumbfuck

Using [] is just syntactic sugar for *, and if you don't know so, you don't know C
>>
>>52574738
Doesn't that have different semantics than char *str? i.e., stack allocation vs heap allocation.
>>
>>52574749
The whole argument is that avoiding * makes your code better, which it does. No one calls an array a level of indirection.
>>
>>52574729
array[4] is literally *(array + 4)
stop being stupid
the only reason this exists is so you don't have to type
*(*(*(arr+a)+b)+c) instead of arr[a][b][c]
>>
>>52574754
>which it does
How so?

>No one calls an array a level of indirection
It's a standard form of storing contiguous information, off course no one's going to avoid using it or shittalk it.
>>
>>52574758
Yes and the point is once you've needed to type * your code is already going downhill. Not to mention ** and ***

>>52574760
Because it makes it harder to understand
>>
>>52574752
>stack allocation vs heap allocation.
That's pretty much the only difference.
When you reference a [] variable, it takes the pointer of it.
>>
>>52574764
>Because it makes it harder to understand
How so?
>>
>>52574764
>Yes and the point is once you've needed to type * your code is already going downhill. Not to mention ** and ***

A non-C programmer is telling C programmers how to write C.
why am i even replying
>>
>>52574770
Because you have to jump through indirection in your brain

>That's easy

Not the point
>>
>pointers are bad because I can't understand it
who let the girl coders in?
>>
>>52574776
Honestly if you can't keep track of 3 levels of indirection, a typical amount, you're a retard.
>>
>>52574776
>Because you have to jump through indirection in your brain
You have to use your brain for many programming-related things, 1-3 levels of indirection is comparatively simple if you understand addresses and memory
>>
>>52574784
Please don't advocate three star programming

See >>52574657
>>
This thread is getting feminine as fuck.
>>
Reminder that pointers are also good for creating data structures such as linked lists and also passing functions to other functions if needed
>>
>>52574766
char *foo = "Hello, world!";
char bar[] = "Hello, world!";

foo[0] = 'a'; /* works fine since foo is a copy */
bar[0] = 'a'; /* runtime error since bar is const */


I would say it's a pretty big semantic difference. You can't just exchange * for [] everywhere.
>>
>>52574792
Forcing yourself to jump hoops in order to avoid pointers where pointers are useful will make your code even messier. Pointers are only "hard to understand" because it's a new concept to you
>>
>>52574801
Shit, I mixed up the comments but you get the idea.
>>
>>52574785

People who don't understand addresses and memory should not do any programming of any sort.

>>52574798

Shhh... babby C programmer doesn't believe indirection is needed for anything. Abstract Syntax Trees for language interpreters? Those aren't real.
>>
>>52574798
But ultimately unnecessary

>>52574805
There are no hoops to be jumped when not using pointers. Pointers are hoops.

>>52574816
>Tripcode

Post discarded
>>
>>52574828
Really? You think implementing a linked list would be easier with an array rather than pointers?
>>
>>52574828
>There are no hoops to be jumped when not using pointers.
Alright then, explain how you would implement the following:
Linked list
Vector
Nodal trees
A game mechanic where you want to move towards the nearest type of entity who has a variable set to a certain value
>>
File: 8d9MxXY.png (646 KB, 1200x1200) Image search: [Google]
8d9MxXY.png
646 KB, 1200x1200
>>52574828
>>
>>52574850
>>52574855
Not doing your homework for you.
>>
>>52574863
You could have tried trolling harder, I'm sure there are some arguments against pointers somewhere, but you presented none
>>
>>52574828
Pointers are also fast (and necessary for systems programming languages to introduce to the programmer in order to all significant control over memory and performance)
However yes I disagree with "3 star programming", pointers should be kept to objects that aren't copied and to out-parameters if you can't just return a tuple.
>>
>>52574863
Good to hear you were baiting this whole time
>>
>>52574876
Calm down Ruby.
>>
>>52574905
I'm chip-8 guy you melt
>>
>>52574910
post the pretty girl pls :3
>>
>>52574910
Who?
>>
File: 1451683583776.gif (2 MB, 400x600) Image search: [Google]
1451683583776.gif
2 MB, 400x600
>>52574926
let's stop arguing about pointers lads
>>
>>52574938
I want to vomit every time I see a white woman
>>
File: 1437519264846.jpg (115 KB, 640x960) Image search: [Google]
1437519264846.jpg
115 KB, 640x960
>>52574926
>>
>>52574954
tfw no milkcow gf
>>
>>52574949
I want to vomit every time I see a 3D woman.
>>
>>52574949
Why so racist, bruh
>>
>>52574977
>Straight white male calling me a racist

:')
>>
>>52574938
>>52574954
hnnng ty
>>
File: 1451683513443.gif (2 MB, 400x225) Image search: [Google]
1451683513443.gif
2 MB, 400x225
>>52574991
Alright, weekend's here, going to really put effort into how I'm going to make a chip-8 zelda interesting with how restricting the architecture is. I suppose it's a decent enough challenge before moving on
>>
>>52574983
I'm a woman you dolt
>>
File: 1446961914142.jpg (35 KB, 479x719) Image search: [Google]
1446961914142.jpg
35 KB, 479x719
>>52575007
why dont you just become a respected tripfag?
>>
>>52575028
I haven't achieved nearly enough for my input to mean anything
>>
>>52575053
That's the wrong attitude anon

the idea of tripfagging is to do it even, nay especially, when literally fucking no one cares about your opinions
>>
>>52575022
i'm a a gril too, but only when i'm wearing a skirt :3
>>
>>52575175
boi pussy pls, i can teach you c
>>
File: fuck.png (98 KB, 1160x1084) Image search: [Google]
fuck.png
98 KB, 1160x1084
how do I get over writing shitty code as a beginner and not knowing how to make it less shitty? should I just leave it be and focus on results rather than the quality of code?
>>
>>52575175
>only when i'm wearing a skirt

how often is that?
>>
>>52575238
don't repeat yourself
>>
Just getting into webdevelopment and webservices, how the fuck do you change your home network from public to private in windows 8.1?

This really should not be very complicated yet all the three page tutorials describing how to lack the actual options described as required to this.q
>>
>>52575274
this is the programming thread, not web dev
>>
>>52575274
jesus christ
>>
>>52575238
To a point I think you shouldn't care how pretty your code is on the first go. I rather see something working than bunch of pretty/clever code that doesn't quite do anything useful yet.

In my opinion programming is iterative process, which to me means working over (refactoring) existing code base from time to time. When you are starting a project you will make mistakes, no matter how hard you think. Something will come up that you didn't anticipate and you can't adapt to it before hand, so you make due with what you can. You write your code the best way you know how at the moment fully acknowledging that you made at least couple dozen horrible mistakes and you'll be back some day fixing it either laughing at yourself for silly mistakes or cursing yourself for trying to be overly clever and not documenting the code.
>>
>>52575291

Yeah, but you see I have written an android app and a number of webservices that all hinge on this.
>>
>>52575291
Do you really feel like there's a difference? Like just because someone writes in PHP, Ruby, Python or JavaScript they aren't "programmers"?

I get that part of developing websites isn't necessary programming. Like designing page layouts or fiddling with CSS, but do you really feel like: "unless it's compiled, it ain't programming"?
>>
File: 1419224427969.png (47 KB, 600x438) Image search: [Google]
1419224427969.png
47 KB, 600x438
>>52574039
>>52573660
>tfw finally found out what was causing this
>tfw it was some DLL that had attached itself to my IDE
I thought I was LITERALLY going crazy
jesus christ
>>
>>52575407
>unless it's compiled, it ain't programming

All of the languages you mentioned have compiled implementations.
>>
>>52575438
For web thou?
>>
>>52575407
Nah, they're not programmers, but they're still coders
This is like getting mad that it's not right to call physical engineers chemical engineers, by the way. It doesn't make it any less of a valid job, you just literally aren't a programmer.
>>
File: 1375391643724.jpg (11 KB, 251x242) Image search: [Google]
1375391643724.jpg
11 KB, 251x242
>>52575464
>they're not programmers, but they're still coders
That's the same thing.
>>
>>52575477
Programmers use programming languages
Coders are people who are writing in any language
Scripters are people that use scripting languages
git gud
>>
>>52575455
Yes.

PHP: HHVM
Ruby: JRuby
Python: CPython
JavaScript: V8
>>
>>52575489
>using the word coder unironically
how feminine of you
>>
>>52575489

I speak English, therefore I am a coder

I've been coding since I was 14 months scrub do you even noscope?
>>
>>52575489
Are you the same guy that talks about flicks and kino and cinema on /tv/? That's just as retarded.
>>
>>52575464
So what a programming language is something that compiles into a binary as its primary way of execution? Or how would you describe a programming language?

Like I can admit freely that most days I don't do programming anymore. I work as a tester, so I mainly just write scripts to assist me or to automate things.
>>
>>52575507
OK. I stand corrected (as usual). I never really thought about it, I guess.
>>
>>52575438
There are interpreters for C and C++. Are those scripting languages now?
>>
>>52575438
all languages can be compiled to a certain extent, depending on your definition of compile. in some cases (bash) there's just no reason to do so.
>>
>>52575571
ADDENDUM http://www.linux-magazine.com/Online/Features/SHC-Shell-Compiler
Thread replies: 255
Thread images: 31

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.