[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: 27
File: 1454870132974.jpg (97 KB, 640x640) Image search: [Google]
1454870132974.jpg
97 KB, 640x640
Old >>54718122

kys edition
>>
>array of arrays
>ARRAY
>OF ARRAYS

>multi-dimensional array
>MULTI-DIMENSIONAL
>ARRAY

know the difference

fucking retarded C spergs
>>
big dick playa here, careful what you say or you'll get rekt hard
>>
>>54724596
STFU retarded.
>>
>>54724596
Original code was in C dumbass
>>
>>54724613
kys

>>54724618
kys

>>54724622
kys
>>
>>54724596
there's no difference tho
>>
>>54724629
tard, I already slapped your face with my big dick, when are you gonna learn?
>>
>>54724650
weak as shit trolling fuck off to /b/ or reddit or something
>>
lets be fucking real C# really is a comfy language whether you like it or not. Its syntax is straightforward, has many diverging functions, #diversity, and is getting more and more popular. And LINQ is based as god. The language is basically wisywig, no bullshit about it.

Why the hate fellas? Seriously...
>>
>>54724666
why do you want me to leave? can't take this huge dick in your mouth anymore?
>>
>>54724672
>VM language
kys
>>
>>54724672
>stale pasta
>>
>>54724596
Topkek, there is literally no difference.
>>
>>54724699
>hurr durr
kys
>>
>>54724699
[ , ] != [ ] [ ]
>>
>>54724715
>[,]
get a load of this webshit
>>
>>54724596
>C
>array of arrays
This is about as retarded as going into a Java thread and talking about pointers, or going into a Python thread and talking about static typing

kys
>>
>>54724715
Yeah, the left one isn't even valid syntax, nice job.
>>
>>54724715
>[ , ]
>shitposting about a language you don't know
kys
>>
>>54724724
fucking IDIOT, in C you still have arrays of arrays, like a two star pointer with separate malloced arrays, or an array of pointers, that's not a contiguous multi-dimensional array
>>
>>54724724
>This is about as retarded as going into a Java thread and talking about pointers
What Java calls references are actually pointers without arithmetic.

>or going into a Python thread and talking about static typing
Since version 3.5, Python supports static type hint annotations.
>>
>C spergs are so stupid that even distinguishing between multi-dimensional arrays and arrays of arrays is too confusing for them
no wonder you hate OOP lmfao you're stupid as hell
>>
>>54724746
Those are dynamic arrays, not regular arrays dumbass.

Be explicit otherwise you're shitposting
>>
File: b8DeepSea.png (256 KB, 600x386) Image search: [Google]
b8DeepSea.png
256 KB, 600x386
>>54724762
3/10
>>
>>54724758
Still not pointer control

Still only hints, and has no effect on interpretation
>>
>>54724746
>in C you still have arrays of arrays
yes
>or an array of pointers
pointers are not arrays
>>
>>54724765
you can have a dynamic multi-dimensional array idiot

if it's not contiguous it's not one array, it's multiple arrays, hence array of arrays
>>
>>54724783
>pointers are not arrays
they are
>>
>>54724765
>Those are dynamic arrays
no
>>
>>54724786
>you can have a dynamic multi-dimensional array idiot
we were talking about non-dynamic multi-dimensional arrays retard
>>
>>54724783
array of pointers to arrays obviously DUMBASS
>>
>>54724804
those are not arrays of arrays, dumbass
>>
>>54724803
kys
>>
File: kek.gif (3 MB, 250x201) Image search: [Google]
kek.gif
3 MB, 250x201
>>54724798
Look at this faggot.
No they aren't, sweetie.

Array to pointer decay is literally C 101.
>>
>>54724803
we weren't specifically talking about non-dynamic arrays only, delusional retard, and even so, it doesn't make any difference, it's retarded to say "dynamic arrays" for everything with no distinction between contiguous multi-dimensional arrays and arrays of arrays
>>
Why are all web "developers" so shit at creating quality code?
>>
>>54724804
so arrays of pointers, not arrays of arrays, fucking retard, kys
>>
>>54724798
>I don't know what I'm talking about
ok
>>
>>54724829
>didn't even see the original code before shitposting
kys

>>54724830
>still pushing this meme
kys
>>
a c++ function that takes an int array as input and saves them in a new array.
if number is is even the number occurs twice.
if not, than not.

int * mult(int* arr,int len,int j) {
int k;
int* res = new int[len*2];
for (int j = 0,k=0; k<len; j++,k++)
{
if(arr[k]%2==0) {
res[j]=arr[k];
res[j+1]=arr[k];
j+=1;
}else res[j]=arr[k];
}
return res;
}


this is a length function without an ext. lib
int len(int *a,int i ) {
if(a[i]) return i+len(a+1,i++);
return i;
}


   input[ ] = {1,2,3,4,5,6}

output: 1 2 2 3 4 4 5 6 6
len(output) = 9


int mult is bit ugly imo with int j and k but im still learning. pointers slowly get into me
/blog
>>
>>54724826
>Array to pointer decay
there's no such thing
>>
>>54724832
>HURRRRRRRRRRRRRRR

nice moving the goalposts

the other day you were saying that your separately malloced shit was a multi-dimensional array but now it's just pointers lmfao you C tards can't even agree on your disgusting shit

kill yourself
>>
>>54724836
>>54724826
but they are, though
>>
This is how you declare multi-dimensional dynamically allocated arrays in C.
int **arr = (int **) malloc(sizeof(int *) * x);
int i;
for (i = 0; i < x; i++)
arr[i] = (int *) malloc(sizeof(int) * y);

arr[x][y] = 32;

Everything else is undefined behavior.
>>
>>54724858
>moving
>he says, changing arrays of arrays to array of pointers
kys
>>
>>54724829
>no distinction between contiguous multi-dimensional arrays and arrays of arrays
correct
>>
File: 921449.jpg (50 KB, 479x583) Image search: [Google]
921449.jpg
50 KB, 479x583
>>54724856
>>54724865
That's some pretty weak b8, anon.
Just denying reality isn't going to cut it.
>>
>>54724853>>didn't even see the original code before shitposting
LITERALLY KILL YOURSELF YOU INSUFFERABLE RETARD

SEE: >>54720667

YOU'RE SIMPLY WRONG

KILL YOURSELF RETARD
>>
>>54724865
not at all, kid
>>
>>54724870
and you say C isn't shit when this is the quality of the language and its users LMFAO YOU'RE A FUCKING JOKE DUDE
>>
>>54724866
>fragmenting your heap
kys

>>54724883
>excessive caps locks
kys
>>
>>54724866
that's not a multi dimensional array
>>
>>54724866
weak bait
>>
File: WHAT WOULD I EVEN DO.png (103 KB, 268x290) Image search: [Google]
WHAT WOULD I EVEN DO.png
103 KB, 268x290
Hey guys!

My friend showed me /g/ a while back. I've been lurking forever until now.

I'm learning Python using codeacademy. My friend (who encouraged me to learn so he could help me with Programming projects and vice versa) is a bit busy right now and can't answer all my questions.

Language seems amazing so far, nothing is explicitly typed and it's super easy to use everything.

The only other languages I know are Basic and Java, what should I be looking to use Python for that the others are subpar at?

>inb4 Pajeet
Nope sorry, just a CompSci student
>inb4 it's not REALLY CompSci, it's just Programming
That's the term everyone else uses, I'll use it too.

Thanks in advance /g/!
>>
>>54724899
>its users
yes, users such as yourself are retarded, I never denied that
>>
>>54724911
This.
It's a pointer to an array of pointer to arrays of ints.
>>
>>54724924
kill yourself pathetic retard
>>
how can i know the number of elements in an array if i don't know how many it will have?

like


int array[] = {1,2,3,4,5,6,7,8};

for (int i = 0; i < array_size; i++ )
printf("%d", i);

// array_size ?

>>
>>54724932
>yes, I am a retard and I got rekt
I know
>>
>>54724922
Mathematic/Scientific computation
Deep/Machine learning
Big data
Image manipulation algorithms
Anything really
>>
>>54724922
>what should I be looking to use Python for
nothing, it's complete and utter shit
>>
>>54724952
ahahah
>>
>>54724911
Yes?
It's a 2D array.

Here's a 3D array!
int ***arr = (int ***) malloc(sizeof(int **) * x);
int i, j;
for (i = 0; i < x; i++)
arr[i] = (int **) malloc(sizeof(int *) * y);
for (i = 0; i < x; i++)
for (j = 0; j < y; j++)
arr[i][j] = (int *) malloc(sizeof(int) * z);

arr[x][y][z] = 32;
>>
>>54724939
8
>>
>>54724952
kys
>>
File: 1383198137036.jpg (90 KB, 960x720) Image search: [Google]
1383198137036.jpg
90 KB, 960x720
What I love about /g/ is the quality posts and informed discussion.

t. Nobody ever.
>>
>>54724946
stay delusional fucking idiot

you're the one who can't distinguish between different simple concepts and you use fucking C when you have no business using it, and you write memory-fragmented shit while delusionally thinking your performance is good lmfao kill yourself
>>
>>54724965
>It's a 2D array
you are mistaken
>Here's a 3D array!
also wrong
>>
File: fml.png (2 MB, 1706x998) Image search: [Google]
fml.png
2 MB, 1706x998
>>54724952
Why anon?

Everyone has a favorite language, my friend's is Python.

It feels better than Java, which I know is a huuuuuuuuuuuge meme around here.

(It's also used to run Toontown, which I want to be a dev for)

>>54724950
Why Image manipulation?
>>
>>54724973
why are you still pretending not to be aware of the size of my dick? really, you're just embarrassing yourself, anon
how many more times do you want me to rape you?
>>
>>54724965
using malloc that way is not guaranteed to be contiguous.

For example, arr[i][3] (element 0) might not start immediately after arr[i][2] (element y).

An int pointer to arr[i][2][y] which is modified by the "++" postfix won't necessarily point to arr[i][3][0].

That's the difference between arrays of arrays and arrays of pointers.
>>
>>54724998
>Why Image manipulation?
pillow library and the like
>>
File: isnt that awesome.png (233 KB, 421x476) Image search: [Google]
isnt that awesome.png
233 KB, 421x476
>>54725012
I don't think I stressed how new I am, I haven't used any library except math.

I'd google it, but I have a feeling you could give me a better answer
>>
>>54724855
what's the int j doing in the method parameters?
>>
>>54725030
quick overview: https://pillow.readthedocs.io/en/3.2.x/handbook/overview.html
>>
>>54725002
Why does it need to be continuous?
Even if they don't read continuously, it's all allocated in a continuous block of memory for the entire structure.

Also, what fucking language automatically increments the subscripts for you?
I've never seen that before.
>>
>>54724786
>not contiguous
>hence array of arrays
arrays of arrays are contiguous tho
>>
>>54725069
>contiguous
it's called a multi-dimensional array
>>
>>54725068
>continuous
>continuously
>continuous
We're talking about arrays, they are contiguous you dumbfuck
>>
VxWorks is pissing me off. I've got this function that gets hooked onto any syscall that gets made, using the syscallEntryHookAdd function. The syscall passes it a struct containing the arguments, the syscall number, the user stack register and frame register, the return address, and the user status register. What I don't get, is any other relevant information about the real time process that made this syscall.

Here's the problem: Kernel uses physical addressing, RTP uses virtual addressing. I can't read from the RTP's buffers to get, say, a filename, without translating the address with vmTranslate. This would be all well and good if I could get the virtual memory context from the syscall. I can't even get a task ID from the syscall information to possibly use to get a virtual memory context (although I can't find any of that information in the many layered struct that is the task control block).

And to make matters worse, all of the documentation from WindRiver is shit.
>>
>>54725089
kys
>>
>>54725083
yes, an array of arrays is a multidimensional array
>>
>>54725089
Every row is continuous.
Every column is just a pointer to a row, how do you not understand this?
>>
>>54725117
Every row is contiguous you dumbfuck, kys
>>
>>54725108
Are you running on x86? If so just look at CR3 ...
>>
>>54725068
>Why does it need to be continuous?
so that you can use pointer math to move around the array.

adding to a pointer should point to the next available location in the array.

so if you're at [i][j][k], incrementing (by whatever method) should be [i][j][k+1], then [i][j][k+2] and so on, until the dim edge where'd you then move to [i][j+1][0].

Because the entire array is contiguous. This wouldn't work in your case because calling malloc multiple times, even with nothing in between, is not guaranteed to return results that are contiguous in memory (more precisely, virtual address space).

You should also be able to do
pointer + (sizeof(k_dimension)) to move from [i][j][k] to [i][j+1][k], and similarly to above this wouldn't work in a non-contiguous array.
>>
>>54725117
Every row is still a number of separated elements, thus they are contiguous, not continuous
>>
>>54725108
>
are you using this guide?
http://www.uio.no/studier/emner/matnat/fys/FYS4220/h11/undervisningsmateriale/laboppgaver-rt/vxworks_kernel_programmers_guide_6.2.pdf
>>
Scripting languages are really good at prototyping.
A lot of people end up shipping their prototype, and then it becomes a nightmare to maintain and people just stick with making changes to the prototype instead of building the real system.
Java is good if you want to build it put it on a bunch of different systems, but you should probably learn a compiled language if you want to progress into the fast and native applications.
>>
>>54725197
>nightmare to maintain
kys
>>
>>54725218
you might be too young to remember, but python decided to change the entire language, so people who made something for version 2 couldn't easily be ported to version 3.
It took a long time for the ones who did, but a lot of projects haven't gotten around to that yet.
>>
>>54725252
>couldn't easily be ported
>what is 2to3
fuck off
>>
>>54725252
My job is working with large python projects, about 120 of them. Hard to maintain is a meme, kys
>>
>>54725270
can you please, please, suck my dick?
>>
why is everyone so hostile here?
>>
>>54725282
>stop raping me
:^)
>>
>>54725274
>My job is working with large python projects, about 120 of them.
interesting.
do you use any IDE or text editor? what about version-control?
>>
>>54725283
because they're retarded mouthbreathers that get defensive when the big dick playa shows them their place
>>
>>54725283
People here are super insecure and need to shout the loudest that they're the best.
>>
>>54725312
IDE - PyCharm using our own license server. I personally use Sublime for medium-sized independent scripts that I can't be bothered to just add into a PyCharm project.

Version Control - Git + beanstalk for deployment
>>
>>54724855
void mult(void *dst, const void *src, size_t elemsz, size_t len,
void *tmp, int (*iseven)(const void *),
void (*copy)(void *, const void *, size_t))
{
for (size_t i=0; i<len; ++i) {
copy(tmp, src, elemsz);
switch (iseven(tmp)) {
case 1: copy(dst, tmp, elemsz), dst = (void *)((char *)dst + elemsz);
case 0: copy(dst, tmp, elemsz);
}
dst = (void *)((char *)dst + elemsz);
src = (void *)((char *)src + elemsz);
}
}

Enterprise Generic Extendable Version.
>>
>>54725116
kys
>>
>>54724965
a 100x100x100 3D array would require 10,000 malloc calls, what the fuck dude
>>
>>54725347
>case 1: copy(dst, tmp, elemsz), dst = (void *)((char *)dst + elemsz);
>case 0: copy(dst, tmp, elemsz);
That's a nice fallthrough you got there.
>>
>>54724596
There are no true arrays in C
>>
>>54725374
Incorrect.
>>
>>54725374
>There are no true arrays in C
what did he mean by this?
>>
>>54725362
Yes.
>>
i am one of the original people who forced the dat boi + kys meme in /dpt/

ask me anything
>>
>>54725392
HERE COME DAT BOI
>>
>>54725392
no you're not. that was me.

ask me anything
>>
>>54725391
It's a shame you didn't use an if instead of wasting a line with a switch.
>>
File: 1451754656609.png (14 KB, 418x359) Image search: [Google]
1451754656609.png
14 KB, 418x359
>>54725392
What do you think of my superior dark pepe meme?
>>
>>54725401
???
>>
File: 1461861230795.jpg (2 MB, 2448x3264) Image search: [Google]
1461861230795.jpg
2 MB, 2448x3264
>>54724576
Hello /g/, I come to you looking humbly for advice and I feel like this is more targeted than /sqt/.

I would like to get into kernel development, device drivers maybe etc. I know that I need to delve further into C, however I was wondering what the best path would be.

Are these books useful?
http://shop.oreilly.com/product/9780596005658.do
http://shop.oreilly.com/product/0636920026891.do

Are there any others I should look into? I'd be buying second hand or during one of oreilly's frequent 50-60% off ebook type of deals.

Finally are there any kernel developers would would stoop so low as to still be on /g/ after becoming successful that have any advice?

Thanks!
>>
>>54725361
>100x100x100 3D array would require 10,000 malloc calls
no, just one
>>
>>54725406
This is 4 lines:
switch (iseven(tmp)) {
case 1: copy(dst, tmp, elemsz), dst = (void *)((char *)dst + elemsz);
case 0: copy(dst, tmp, elemsz);
}


This is three:
if (iseven(tmp) == 1)
copy(dst, tmp, elemsz), dst = (void *)((char *)dst + elemsz);
copy(dst, tmp, elemsz);


Both are equivalent.
>>
>>54725399
kys senpai

>>54725404
who is dat frogg?
>>
>>54725383
Pass an array to a function then, faggot.
>>
>>54725374
>I don't know C
>>
>>54725411
eudyptula-challenge.org
>>
Guys i have a final coming and pic is the stuff im tested on. should i worry?
>>
>>54725423
???
>>
>>54725423
not really, the first one is safer because if you extend iseven to return something other than 1 or 0 then it won't do anything while the second one will erroneously run the 0 branch. you have to think extensibly!
>>
>>54725434
I did.
>>
>>54725445
>tested on nothing
lucky bastard
>>
File: Capture.png (7 KB, 270x109) Image search: [Google]
Capture.png
7 KB, 270x109
fug, heres pic
>>
>>54725434
Non-sequitur.
C has "true functions" as well as "true arrays", and you can't pass either to a function.
The fact that they are manipulated through pointers do no make your "no true scotsman" fallacy any more valid.
>>
>>54725458
You didn't
>>
>>54725411
http://www.amazon.com/dp/0201433079/?tag=stackoverfl08-20
http://lwn.net/Kernel/LDD3/
http://kernelnewbies.org/
http://www.amazon.com/dp/0672329468/?tag=stackoverfl08-20
http://eudyptula-challenge.org/
http://www.tldp.org/LDP/lkmpg/2.6/html/index.html
http://wiki.osdev.org/C++
http://www.cs.vu.nl/~herbertb/misc/basickernel.pdf
https://kernel.org/doc/Documentation/HOWTO
http://www.osdever.net/bkerndev/Docs/creatingmain.htm
http://programmers.stackexchange.com/questions/52729/how-to-become-a-kernel-systems-device-driver-programmer
http://kernelx.weebly.com/tutorials.html
>>
>>54725464
>recursion
tell your teacher that your final is a meme
>>
>>54725478
I did.
>>
>>54724939
you literally cant welcome to C.
>>
>>54725493
>I don't know any math, the post
>>
>>54725347
thanks!
but i have no clue what a const void or size_t means

>>54725051
good question.
i think i wanted to include the length - function in the *mult function

int lng(int *a,int i ) {
if(a[i]) return i+lng(a+1,i++);
return i;
}

int * mult(int* arr,int len,int l) {
int j;
int k;
int* res = new int[len*2];
for (int j = 0,k=0; k<len; j++,k++)
{
if(arr[k]%2==0) {
res[j]=arr[k];
res[j+1]=arr[k];
j+=1;
}else res[j]=arr[k];
} cout << " LÄNGE " << lng(res,l) << endl;
return res;
}
>>
File: 1463595953646.png (5 KB, 64x64) Image search: [Google]
1463595953646.png
5 KB, 64x64
>>54725479
>>54725442
I didn't expect this much and especially so quickly, thank you anons!
>>
>>54725434
void f(int x); // only accepts arrays of length 1
>>
>>54725473
>The fact that they are manipulated through pointers do no make your "no true scotsman" fallacy any more valid.

It does. Passing the size of the array as a separate value means that array in C are arrays-but-not-quite. C is simply a retarded language.
>>
>>54724939
size_t array_size = sizeof(array)/sizeof(array[0]);


Or in a modern language:

auto array_size = std::extent<decltype(array)>::value
>>
>>54725499
You passed a pointer, dumbass.
>>
>>54725542
>It does. Passing the size of the array as a separate value means that array in C are arrays-but-not-quite. C is simply a retarded language.
C gives you the choice of wether you want to pass the size or not, because sometimes you don't need to. And when you do need to, you can chose how it will be done.

If you want high level handholding abstractions, C is not what you're looking for.
Don't blame the tool for your misunderstandings.
>>
>>54725401
>>54725423
>if without braces
Ctards everyone
>>
>>54725612
>I can't think for myself so I follow antiquated style guides religiously
Kek.
>>
>>54725548
what's your definition of ``modern''?
>>
>>54725505
yes
>>
>>54725612
what's the matter? its allowed when you have one statement faglord
>>
>>54725633
Released in 2010+4.
>>
File: [tilting increases].png (27 KB, 500x500) Image search: [Google]
[tilting increases].png
27 KB, 500x500
>>54725626
>>54725643
>i'm literally stupid as hell so i'm going to write whatever garbage code i feel like writing
kys
>>
>>54725654
>I'm so inept the slightest amount of variation is enough to trip me up
>Please give me easy monkey job
>>
>>54725671
keep writing amateur shit code idiot
>>
#include <stdio.h>
#include <inttypes.h>

int main(void) {
uintptr_t *p;
p = (uintptr_t *)&p;
*p = (uintptr_t)p;
printf("%p -> 0x%"PRIxPTR"\n", p, *p);
return 0;
}
>>
File: C anime2.jpg (332 KB, 1200x2133) Image search: [Google]
C anime2.jpg
332 KB, 1200x2133
Friendly reminder that C is being taught in japan as a toy language for 12 year olds.
>>
>>54725599
You can pass a struct as a pointer if you don't want to deal with the overhead of passing everything by value.
You could implement a true array like a struct with a field size and a pointer, it's not rocket science and does not kill performance.
But no, C tards thinks this is an incredible level of abstraction.
They will be killed when a non.retarded systems programming language comes along and they will not be missed.
>>
>>54725654
well i make 96K USD / year as embedded systems developer write if statements without braces all the time.
my boss doesn't care.

stay mad NEET
>>
>>54725701
>wagecuck
kys
>>
>>54725542
>array in C are arrays-but-not-quite
arrays in C are arrays tho
>>
/g/ do i need to wrap the background in a div as well? (Trying to make 1box site. Just a box at the middle of the screen with with my H1 and P) Or can i just style and position the box and define background align and that's it?

<html>
<head>
<title> Testowe gawno </title>
</head>
<body>
<div id="Box">
<h1>Main header</h1>
<p>Main paragraph</p>
</div>
</body>
</html>

I got this so far
>>
>>54725683
Oh wow, you called me an idiot! That totally changed my views.
If you can't cope with single line if statements, I guess it's a good thing you stick to safe baby languages.
>>
>>54725553
I did no such thing.
>>
File: python-vs-java-726367-copy.jpg (53 KB, 621x408) Image search: [Google]
python-vs-java-726367-copy.jpg
53 KB, 621x408
Currently trying to learn C, but this shit looks so disgusting to me after I've coded with Python only for 1 year...
>>
>>54725718
And they get demoted to pointers every time they get passed to a function, because "reasons".
>>
>>54725708
ahahah

loving every second. keep'em comming NEET
>>
>>54725699
>could implement a true array
no need, C has true arrays
>systems programming language comes along
>muh golang
top fucking kek
>>
File: 1363718652841.jpg (91 KB, 706x720) Image search: [Google]
1363718652841.jpg
91 KB, 706x720
>>54725699
>You can pass a struct as a pointer if you don't want to deal with the overhead of passing everything by value.
>You could implement a true array like a struct with a field size and a pointer, it's not rocket science and does not kill performance.
That would be a mistake, the cost of the extra dereference is more than the cost of passing an extra argument, especially with modern x64 calling conventions.

>But no, C tards thinks this is an incredible level of abstraction.
>They will be killed when a non.retarded systems programming language comes along and they will not be missed.
You like to throw insults around, but all I'm seeing is a little pussy at peak Dunning-Kruger.
>>
>>54725787
>the cost of the extra dereference is more than the cost of passing an extra argument
No, it depends on how the compiler optimize it. A good compiler may transform one into another.
>>
>>54725745
>they get demoted to pointers
no true, there' no "demotion"
>>
>>54725787
In a non-trivial program, a struct contains more bits than a single 64-bit character address.

Also, what if I actually wanted to to change it's contents?
>>
File: 1454870132974.png (1 MB, 640x640) Image search: [Google]
1454870132974.png
1 MB, 640x640
>>54724576
>>
>>54724576
compsci student trying to figure out what electives to choose. I'm considering graphics programming or a general C++ course. Any advice?
>>
>>54724856
https://web.archive.org/web/20081208122434/http://www.transcendentaxis.com/dthompson/blog/archives/9
>>
>>54725787
>That would be a mistake, the cost of the extra dereference is more than the cost of passing an extra argument, especially with modern x64 calling conventions.

And if you want the extra performance use a fucking pointer instead. Plus optimizing compiler could do the job instead.

In fairness arguing with C cucks is useless.
You could have the same semantics of C without the retardeness of C, but no, let's stick to a language designed for computers with KBs of memory.
>>
>>54725839
>archive cache of a "not worthy to be hosted anymore" blog
>C++
we're talking C, retard, try to keep up
>>
>>54725868
>muh jvm warmup time doesn't count tho
webshits, everyone!
>>
>>54725838
Do what interests you. I took graphics and it was pretty cool.
>>
>can't make a function pointer to a method in class in C++
Fucking annoying as hell. Every time I'm programming in C++ I run into a class problem that isn't a problem with C structs.

Does anyone else feel like the classes in C++ treat you like a monkey? I feel like it's just a safer version of a struct, with some conveniences like constructor/destructor. Inheritance also feels inferior to C struct composition.

>>54725787
>the cost of the extra dereference is more than the cost of passing an extra argument
Shitt not the other guy but I never knew this, reading into it now.
>>
>>54725872
I knew you would say that :^)

It's applicable to C as well. You just embarrassed yourself.
>>
>>54725813
>A good compiler may transform one into another.
It may not, because in the general case it's impossible to prove that the function you're passing your array to is not used by another function that did respect the calling convention, so the calling convention may not be optimized. If you do the mistake of passing a pointer, the compiler will have to work with your mistake.
And in the case of the function call being inlined, all of this is of course irrelevant since no call is made.

>>54725825
I'm not sure I understand your question, I was talking about passing a {array_ptr; array_size } struct, which should be done by copy.
If you have a large struct unrelated to this that you need to modify, it makes sense to pass it by pointer, yes.
>>
>>54725868
>arguing
>useless
especially when you don't know what the fuck you're talking about and get raped with every inane post you make
>>
>>54725889
it's fucking nothing, IDIOT, and top kek if you're only doing fizzbuzz-tier apps that run for like a fraction of a second
>>
So if you want to have a contiguous multidimensional array why not just alloc sizeof(int)*w*h and index with [y*w+x]? I mean if it's that big of an issue for you..
>>
>>54724676
sup big dick playa
>>
>>54725889
>Java
>same semantics as C

You failed as troll
>>
>>54725902
>applicable to C as well
>muh defunct blog says so
top kek
>>
>>54725923
>what is abstraction
at least make a macro for the indexing
>>
>>54725924
meh, just raping these webcucks, you know, the usual
>>
>>54725937
ofc, not saying you shouldn't
>>
>>54725912
>especially when you don't know what the fuck you're talking about and get raped with every inane post you make

Except that you sizeof(array) gives different results if you pass the array to a function.
No, no C has true arrays I swear.
>>
How do you mutate data in a languages without pointers?
>>
>>54725925
>not C
>same semantics as C
you truly are retarded
>>
>>54725957
(setq 'myvar 12)
>>
>>54725944
2tru
>>
>>54725957
You return a new value and overwrite the old, or you secretely have pointers but call them references (HRMJAVAEHM)
>>
DAILY C GENERAL
>>
>>54725916
>REEEEEE
called it! :^)
>>
>>54725937
do you also need a macro for assigning variables, nancy?
>>
>>54725691

What happens when they move on from toy languages like C? Ruby!?
>>
File: VQSucsH.png (228 KB, 858x725) Image search: [Google]
VQSucsH.png
228 KB, 858x725
>>54725978
>secretely have pointers but call them references
NO REFERENCES ARE NOT POINTERS
>>
>>54725951
>sizeof(array) gives different results if you pass the array to a function
not true; go ahead, show me how you pass the array to a function and I'll show you why you're wrong
>>
Do OpenGL red triangle, forget to use glUseProgram, a white triangle appears anyway.
WTF
nividia plz implement spec and not vodoo magic
>>
>>54726010
Everywhere but in Java, references refer to an alias of a variable. In Java, a reference is really just a pointer whole value you can't do math with, but it's not what is commonly understood to be a reference.
/rant
>>
>>54726010
they are tho, albeit with limited power, you know, dumbed down for idiots
>>
>>54726034
you are not knowledgeable enough to make such definitive statements
>>
>>54726032
>muh undefined behavior didn't work as expected
>>
>>54726049
You are not knowledgeable enough to judge me over the Internet, Nameless.
>>
>>54726018
>how you pass the array to a function

function(array) ?
>>
>>54726068
haven't you heard about the size of my dick?
>>
>>54726083
what's the declaration of "function" and what's the declaration of "array"?
>>
File: K&R.png (107 KB, 792x1023) Image search: [Google]
K&R.png
107 KB, 792x1023
Programmer RED FLAGS

>he recommends K&R
>he has memorized all of K&R and idolizes it like a bible
>>
>>54726083
>pass stack array
>sizeof doesn't work anymore
>this big argument

Just make a "struct vector" that suits your needs.

>>54726119
Agreed to be honest. K&R is more of a starting point than a bible.
>>
File: thisIs4chan3.jpg (89 KB, 1016x741) Image search: [Google]
thisIs4chan3.jpg
89 KB, 1016x741
>>54726091
No but I heard about rule 2, you may not use the site if you are under the age of 18.
>>
>>54726119
>he uses C
>he uses python
>>
>>54726135
>No but
that explains it; you see, I'm never wrong; you'll learn this eventually
>>
File: argumentsWon.png (15 KB, 528x434) Image search: [Google]
argumentsWon.png
15 KB, 528x434
>>54726148
>I'm never wrong
Yes, I can see that.
>>
>>54725127

I am in the simulator, but I have no clue what OS this will end up being used for. Most industrial control systems aren't x86, and I don't want to unnecessarily make this non-portable. VxWorks has routeines for portably translating virtual addresses. I just don't have a way of getting the context.

>>54725153

I am using the 6.9 Kernel Programmer's Guide that came with the workbench.
>>
>>54726119
>Programmer RED FLAGS

Spec warrior -- if you suggest any technique which exploits UB, the spec warrior explodes. God forbid you haven't memorized the spec, either, because you'll also get an earful.
>>
>>54726160
kys
>>
>>54726034
>Everywhere but in Java
>and C#
>and python
>and ruby
>and javascript
>and countless others
>>
>>54726160
you can actually feel it too ;^)
>>
>>54726169
>technique which exploits UB
>exploits
codewords for "don't actually know what the fuck you're doing"
>>
>>54726035
you're a useless sack of shit
>>
>>54726111
#include <stdio.h>
#include <stdlib.h>

void print_size(int a[]);

int main(int argc, char* argv[])
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

printf("sizeof array in scope %d\n", (int) sizeof(a));
print_size(a);

printf("GET REKT M8\n");

return 0;
}

void print_size(int a[])
{
printf("sizeof array passed to a function %d\n", (int) sizeof(a));
}
>>
Daily reminder that Java and C# are pass by reference in most cases.
>>
>>54725957
Don't have functions, or scoping.

Subroutines can achieve this.
>>
>>54726251
java is pass by value only kys
>>
>>54726244
you're confused, that code doesn't pass an array to a function, it merely passes a pointer to int
>>
>>54726244
How do you get the size of a malloced array though?
>>
>>54726265
Please don't spread misinformation. Objects are not passed by value.
>>
>>54726233

Fair, but the spec warrior also complains about extensions -- even widely supported ones.
>>
>>54726299
>Objects are not passed by value.

The value of the reference is passed.
>>
>>54726299
Yes they are.
>>
>>54726327
In other words, the object is passed by reference.
>>
>>54726328
>java objects are passed by value\
nope
>>
>>54726279
Which kinda was the point.
>>
File: smh tbh fam.gif (81 KB, 182x249) Image search: [Google]
smh tbh fam.gif
81 KB, 182x249
Why do people recommend "Javascript: The Good Parts"?

It has an entire section dedicated to "the Bad Parts" and it's literally just a list of every C construct in Javascript, it complains about bitwise, incrementers, continue, switches, etc.
>>
>>54726332
get a clue jackass

http://javadude.com/articles/passbyvalue.htm
>>
>>54726119
>C
Enjoy your botnet.
>>
>>54726332

No. Set your "reference" to a new object and see what object you have in the calling scope.

Pro-tip: it's the original one.
>>
>>54726367
Javascript is a great language, you just have to remember to always use ===== because the previous 4 versions of the equality operator were poorly designed.
>>
>>54726381
You made my day.
>>
>>54726343
public class Program {

public static void foo(Object o) {
o = null;
}

public static void main(String[] args) {
Object o = new Object();
foo(o);
if (o == null) {
System.out.println("Java passes objects by reference!");
} else {
System.out.println("Java passes objects by value!");
}
}
}
>>
>>54726369
>javadude
bwahahahahahaha
>>
Recursive function definitions are actually pretty easy to mechanically elaborate to (indexed) W-type elimination.
>>
>>54726400
>look mom i'm getting replies form autists on a neckbeard forum
that is not an argument
>>
>>54726364
>Except that you sizeof(array) gives different results if you pass the array to a function.
>if you pass the array to a function
>pass the array
>doesn't pass the array to the function
m8...
>>
>>54726378
What does this have to do with anything?
>>
GUYS HOW DO YOU PREPARE FOR TEST
>>
>>54726392
You're confusing things anon. But it's funny.
>>
>>54726436
By knowing the curriculum.
>>
>>54726433
do you even know what a reference is in the context of "pass by reference" fucking idiot
>>
>>54726447
>You're confusing things anon.
Nope.
>>
>>54726436
by reading over my notes and marking what i don't know. then i get to class 15 minutes early and look at what i highlighted again to make sure i remember it
>>
>>54726424
Could you pass the array to the function for me?
>>
>>54726447
kill yourself
>>
>>54726436
I don't, I'm self taugh and I have to wait for tests so they'll finally hand me my diploma.
>>
>>54726392
#include <stdio.h>

void foo (int *o) {
o = NULL;
}

int main(void) {
int i;
int *o = &i;
foo (o);
if (o == NULL) {
printf("C passes objects by reference!\r\n");
} else {
printf("C passes objects by value!\r\n");
}
}
Thread replies: 255
Thread images: 27

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

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