Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

whats the purpose of this C function

Name: Anonymous 2007-09-12 5:22 ID:wfxixJ2g

Excuse my newfagedry

Consider the C code function below:
void qwerty(int *x, int *y, int size)
{
 int k=0;
 while ( k < size ) {
    *(x + k) = *(y + k);
    k++;
 }
}

i) What best describes the purpose of the function qwerty?

Name: Anonymous 2007-09-12 12:19 ID:tg2Q+oGx

>>39
ok i'm not a troll, i just did some stupidery by not looking at types.

Name: Anonymous 2007-09-12 14:53 ID:Heaven

/* Standard Version */
#include <string.h>
#define qwerty( x, y, s ) memcpy( x, y, s )

Name: Anonymous 2007-09-12 14:54 ID:Heaven

>>39
PowerPC Mac faggot.

Name: Anonymous 2007-09-12 15:56 ID:i9LZzsvu

>>42
PROTIP: sizeof(int) is usually not 1.

/* Standard Version */
#include <string.h>
#define qwerty(x,y,s) memcpy(x,y,(s)*sizeof(int))

Name: Anonymous 2007-09-12 15:58 ID:PGUchsOe

>>43
My other UNIX is a NUXI.

Name: end 2007-09-12 18:14 ID:tg2Q+oGx

>>45
I lol'd and lol'd and lol'd.  Thank you, >>45
Also, word endianess contains letters dias, which is an anagram of aids.

Name: Anonymous 2007-09-12 21:14 ID:YCRz3nQy

EXPERT PROGRAMMER VERSION
void qwerty
 (int *x, int *y, int size)
    { while(size--) *x++ = *y++; }

Name: Anonymous 2007-09-12 21:21 ID:QQV6F4v3

>>47
Fuck yes, I invented this indentation style. Glad to see it catching on.

Name: Anonymous 2007-09-12 23:53 ID:GS7Cg19P

>>48
How do you indent multiple lines of code then?

Name: Anonymous 2007-09-13 0:16 ID:VlDG1HGa

>>49
You don't!

Name: Anonymous 2007-09-13 0:17 ID:Heaven

WTF TO THE STARS MEAN?! LIKE *x and *y.

Name: Anonymous 2007-09-13 0:25 ID:Heaven

>>51

It means the variable is loaded into the Java VM for garbage collection.

Name: Anonymous 2007-09-13 0:32 ID:Heaven

I ment in a REAL language. like C

Name: Anonymous 2007-09-13 0:45 ID:xRGtEQYH

win32 version:

querty(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, true);

Name: Anonymous 2007-09-13 0:45 ID:Heaven

>>51
 when you put a variable after the star, the star returns the address of the variable.

Name: Anonymous 2007-09-13 0:49 ID:SdzwQKNt

+x is positive x, -y is negative y, *x is multiple x.

Name: Anonymous 2007-09-13 0:49 ID:RN5OLYB3

>>49
I actually do it like this:

void qwerty (int *x, int *y, int size) {
  while(size--) *x++ = *y++;
  if some_bullshit {
    do_some_bullshit(); }}

Kein Problem.

Name: Anonymous 2007-09-13 3:06 ID:liVlMgbD

>>56
int *x returns multiple x

Name: Anonymous 2007-09-13 3:08 ID:za+w4Tbq

yes.  C can assign multiple variables at the same time

Name: Anonymous 2007-09-13 4:16 ID:Heaven

*x = 1,2,"Hello World",strcopy();

printf(%i, x);

Name: Anonymous 2007-09-13 6:46 ID:Heaven

MEMCPY WILL NOT WORK DUE TO ENDIANESS ISSUES YOU FUCKING FUCKTARDS

ALSO >>44 sizeof(int) IS NEVER 1. NEVER.
>>59
NO IT CANNOT

THANKYOU. BYE
FUCKWIDS

Name: Anonymous 2007-09-13 11:54 ID:Kfyw6JKG

ITT OMG OPTIMIZED

Name: Anonymous 2007-09-13 14:23 ID:381I8pvJ

void qwerty(int *x, int *y, size_t s){
 size_t t, l = sizeof(uint64_t)/sizeof(int), size_t m = l - 1;
 if((y | x) & m){
  if((y ^ x) & m || s < l)
   t = s;
  else
   t = l - (y & m);
  s -= t;
  do{
   *x++ = *y++;
  }while(--t);
  t = s / l;
  if(t)
   do{
    *(uint64_t*)x = *(uint64_t*)y; x += l; y += l;
   }while(--t);
  t = s & m;
  if(t)
   do{
    *x++ = *y++;
   }while(--t);
}

Name: Anonymous 2007-09-13 14:24 ID:Heaven

>>63
oops...
void qwerty(int *x, int *y, size_t s){
 size_t t, l = sizeof(uint64_t)/sizeof(int), m = l - 1;
 if((y | x) & m){
  if((y ^ x) & m || s < l)
   t = s;
  else
   t = l - (y & m);
  s -= t;
  do{
   *x++ = *y++;
  }while(--t);
  t = s / l;
  if(t)
   do{
    *(uint64_t*)x = *(uint64_t*)y; x += l; y += l;
   }while(--t);
  t = s & m;
  if(t)
   do{
    *x++ = *y++;
   }while(--t);
}

Name: Anonymous 2007-09-13 16:12 ID:/Rn6s4wx

>>62
I expect full, frank and amusing details by tomorrow, however, and I'll happily return the favour.

Name: Anonymous 2007-09-13 16:17 ID:fyVsToeS

it's the google algorithm

Name: Anonymous 2007-09-13 16:20 ID:X6QNs1Xv

>>61
Let me explain why you are an idiot.

1:
Endianness problems only occur when you switch between different types of endianness. So unless your endianness changes based on the memory address, memcpy works just fine.

2:
In the C and C++ standards the following things are required:
sizeof(char) = 1
sizeof(char) ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long)
char ≥ 8 bits, short ≥ 16 bits, int ≥ 16 bits, long ≥ 32 bits

I quote from http://home.att.net/~jackklein/c/inttypes.html#long : "There is at least one DSP I have worked with where CHAR_BIT is 32. The char types, short, int and long are all 32 bits."

3: I consider struct assignment to be multiple assignment.

Name: Anonymous 2010-12-06 9:26

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2010-12-27 20:21

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List