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

c syntaks

Name: Anonymous 2011-12-17 11:01

what was the easier way to refer to an array's first member other than array[0] ?
i forgot what the symbol was.

Name: Anonymous 2011-12-17 11:02

I mean: first member is array[0]
and there's some other (shorter) way to type it and it's the same thing

Name: Anonymous 2011-12-17 11:09

*array

Don't do this, though.

Name: Anonymous 2011-12-17 11:14

>>3
It's just when i have a function which takes a struct as an argument, if the struct is too large then the program stack overflows and anyway it doesn't even refer to the original struct, just copies it on the stack.
So I have to use pointers or global variables. That shit's gay as hell. Sure there must be a better way to do it?

Name: Anonymous 2011-12-17 11:17

>>4
also, thank god my compiler knows to allocate global variables to heap rather than stack. otherwise i would shoot myself

Name: Anonymous 2011-12-17 11:25

>>4
Try this:

template <class T>
void f( const &T ) {
}

Name: Anonymous 2011-12-17 11:30

>>6
That was supposed to be
( T const &v )

Name: Anonymous 2011-12-17 12:27

0[array] works surprisingly enough.

Name: Anonymous 2011-12-17 12:33

>>6
That's C++ syntax you dumb jew.

Name: Anonymous 2011-12-17 12:38

>>8

#include <stdio.h>
#include <string.h>

char array[] = "HOW AWESOME?!";

int main() {
    for( int i = 0; i < strlen(array); i++ )
        printf("%c", i[array] );

    printf("\n");
    return 0;
}

Name: Anonymous 2011-12-17 12:39

>>7
The question was about C. Not C++. I know they might appear the same to a total dumbass like yourself. But...never mind. Go scrub another toilet you mental midget.

Name: Anonymous 2011-12-17 12:39

>>8
You're dangerously insane!

Name: Anonymous 2011-12-17 12:45

>>11
But I thought C++ was a newer version of C!!!

Name: Anonymous 2011-12-17 12:48

>>10
for( int i = 0; i < strlen(array); i++ )
Well, that's a waste of an O(n) function call per loop.

       printf("%c", i[array] );
Why not just putchar(i[array])??

  printf("\n");
Same as above, use putchar.

Name: Anonymous 2011-12-17 12:49

>>13
Eh? Shouldn't you be helping another customer?

Name: Anonymous 2011-12-17 12:50

>>14
Holy shit you suck. That loop doesn't run in linear time you dumbass.

Name: Anonymous 2011-12-17 12:55

>>14
Well, that's a waste of an O(n) function call per loop.
Nope. JIT will determine, that strlen has no side effects.

Name: Anonymous 2011-12-17 12:57

>>17
JIT
That's C. C is not Java. C has no JIT.

>>16
strlen is linear time.

Name: Anonymous 2011-12-17 13:11

>>14

Lisp   | C/C++
-------|-----------------------------------------------------
format | printf fprintf sprintf snprintf vsprintf vfprintf vsprintf vsnprint
       | asprintf vasprintf dprintf vdprintf wprintf putchar fputchar putwchar
       | putc fputc fputwc puts fputs fputws write fwrite
       | ostream ofstream streambuf streingstream ostringstream stringbuf
       | fstream filebuf ios ios_base cout cerr std clog << endl ends hex oct
       | boolalpha dec flush internal setw noboolalpha noshowbase noshowpos left
       | right resetiosflags scientific setbase setfill setiosflags setprecision
       | showbase showpoint showpos skipws unitbuf nouppercase uppercase ws

Name: Anonymous 2011-12-17 13:14

>>18
C is shit.

Name: Anonymous 2011-12-17 13:19

>>14
The other day I noticed gcc optimizes printf("%c", c); to putchar(c);. I wonder what's up with that, seems a bit too fancy.

Name: Anonymous 2011-12-17 13:26

>>21
bloat in the compiler

Name: Anonymous 2011-12-17 13:39

gcc optimizes printf("%c", c); to putchar(c);.
FUCKING JEW! hate C/C++ so much! Even more than Haskell.

Name: Anonymous 2011-12-17 13:46

>>21
I know it does, but you shouldn't rely on such features, unless you're targeting a specific (version of a) compiler. It's bad practice.
On a side note, it also optimizes the strlen of literals to an int literal, computed on compile time.

Name: Anonymous 2011-12-17 13:57

>>24
What if I link with different runtime?

Name: Anonymous 2011-12-17 15:13

>>14
strlen is pure, so any modern C library will not compute it many times.

Name: Anonymous 2011-12-17 15:52

>>14
I'll tell you why:
I don't code with <stdio.h> all day.
I use <iostream>, but flame wars would ensue if I used it.

Name: Anonymous 2011-12-17 15:58

>>26

for(int i=0; i<strlen(str); i++)
 f(str, i); // if i is even, add two character to str, else remove three

What about now, ``faggot''?

Name: Anonymous 2011-12-17 16:01

>>28
Now you're mutating the string, retard.

Name: Anonymous 2011-12-17 16:04

>>14

#include <stdio.h>
#include <string.h>

char array[] = "HOW AWESOME?!";

int main() {
    register char *c = array;

    while( *c != 0x00 ) {
        putchar( *c );
        c++;
    }

    putchar('\n');
    return 0;
}


ZOMG OPTIMIZED

.

.

.

Seriously, take your shit somewhere else... /polecat kebabs/.

Name: Anonymous 2011-12-17 16:08

>>30
If you just use sizeof(array) the compiler can unroll the loop and it will be even faster.

Name: Anonymous 2011-12-17 16:46

>>26
strlen is pure
I saw strlen being fucked pretty roughly by a gang of niggers once. It was smiling as if it was in heaven and had its eyes rolled back and tongue out while its face was covered in cum and its two holes were being penetrated simultaneously. It was jerking off three other niggers at the same time too, one per hand and one with its feet.

Name: Anonymous 2011-12-17 16:54

>>32

strlen my cock dude

Name: Anonymous 2011-12-17 17:06

>>26
No modern library is clever enough to deduce that strlen is pure, most of them just use a builtin.

Name: Anonymous 2011-12-18 2:03

>>34
From some random glibc version
extern size_t strlen (__const char *__s)
     __THROW __attribute_pure__ __nonnull ((1));

Name: Anonymous 2012-01-13 13:10

This is the first result on Google for "mental midget scrub another toilet".

Name: Anonymous 2012-01-13 13:12

Don't be j.

Name: Anonymous 2012-01-13 13:34

>>17
Java
JIT is shit.

Name: Anonymous 2012-01-13 13:41

>>30
Subtle. Took me some time to realize the pointer is register. But you shouldn't need <string.h>, and I don't see why you didn't further reduce this the loop to

    while(*c)
        putchar(*c++);

Name: Anonymous 2012-01-13 13:47

>>39
strlen

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