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

C Question

Name: Anonymous 2011-07-19 2:02

Im going to be taking Intro to C in the fall so I have decided to read up on the textbook and learn how to program before the semester starts. I'm having a little problem, here's the trouble maker:
    potr1 = &goodarray[0];

    potr2 = &goodarray;

for some reason potr2 gets assigned the value of the &goodarray[0]instead of the &goodarray itself.. I have verified this by printfing both of them and they come up the same number. Im using DevC++ and Im pretty sure I just need to find a better compiler, but am I doing something wrong?

Name: Anonymous 2011-07-21 11:21

>>40
I do not suffer from mental retardation. I enjoy it.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 11:21

>>40
It is pretty relevant because one is a modifiable lvalue and the other one isn't.

Name: Anonymous 2011-07-21 11:27

>>42
I'm just saying that ``the name of an array'' shyte is a flawed notion retards use to distract themselves from their broken mental model of C.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 11:38

>>43

I really hope that you aren't the same person that said the following..

>>30,31

Would foo evaluate to a pointer to the first element of this > array?

Um... Why, yes, it would.

If you did, you are totally clueless about C. When I run something like the following through gdb

#include <stdio.h>

int main(void) {
  char *p;
  char foo[10];
  p = &foo[0];

  return 0;
}


I get 'foo' as

type = char [10]


but 'p' as

type = char *

In other other words, one is an array of 10 char objects and the other is a pointer.

Name: Anonymous 2011-07-21 11:44

>>44
I really hope that you aren't the same person that said the following..
I'm not.

In other other words, one is an array of 10 char objects and the other is a pointer.
Guess what: No shit, Sherlock. Just look up their fucking declarations, cause that's how (explicit) statically typed languages work...

Name: Anonymous 2011-07-21 12:31

The pointer to the first object in an array and a pointer to the array itself is the same value in C (and in most languages I think).  In fact, there's no real distinction between writing to an array and writing to a memory address that's probably being used by a high level process in that exact moment. 

And yes, if that fills your heart with dread, you should be scared.  Be afraid.  Be very afraid.

Name: Anonymous 2011-07-21 13:07

>>46
No, because one points to an array which an unmodifiable lvalue, and the other points to an array element.

Name: Anonymous 2011-07-21 13:13

>>46

#include <stdio.h>

int main(void) {
    char a[10];

    char *p = &a[0];    // a pointer to the first object in an array
    char (*q)[10] = &a; // a pointer to the array itself

    printf("%zu\n", sizeof *p);
    printf("%zu\n", sizeof *q);

    return 0;
}


It's not the fucking same "value", ``faggot''!!!
Now back to the imageboards, please.


IHBT

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 14:14

>>48

char (*q)[10] = &a; // a pointer to the array itself

That's wrong. &a points to the first object in the array named 'a'.

Name: Anonymous 2011-07-21 15:11

>>49
This is getting boring, dude. I've pointed out your stupidity several times now and it _still_ didn't shut you up. I suggest you d/l a copy of the C std and study it for the next, say, 5 years. Maybe it dawns on you, but prolly it won't.

Also, learn how to use code tags, for fuck's sake. Can't even take you serious.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 15:34

>>50
You don't know what you are talking about you stupid hourly worker. Unlike you, I actually do this kind of stuff for a living. Now get lost you fucking minimum wage bitch.

Name: Anonymous 2011-07-21 15:38

>>51
So you're telling me, that you're writing broken C for a living? Exciting!

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 15:45

>>52
No, but I have helped implement working conforming C compilers.

Name: Anonymous 2011-07-21 15:49

>>53
I highly doubt that.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 15:56

>>54
I want to get back to the following...

char (*q)[10] = &a; // a pointer to the array itself


Something like char (*q)[10] is a pointer to char[10]. In other words, it doesn't point to the array itself. The fact that you keep insisting that this is the array itself makes you that much dumber.

Name: Anonymous 2011-07-21 15:58

>>54
Okay, I work Kodak Gallery on Hollis Street here in emeryville. You are more than welcome to come up here and say that to my face you stupid hourly worker bitch.

Name: Anonymous 2011-07-21 16:00

>>52
You could say the same for most C programmers.

Name: Anonymous 2011-07-21 16:03

>>55
Once again, for the mentally challenged:

char a[10];
char (*q)[10] = &a;

a  // "the" array
q  // a pointer to "the" array
*q // "the" array (again)

Name: kodak_gallery_programer !!kCq+A64Losi56ze 2011-07-21 16:06

>>58
Yes, that's correct, but this..

char (*q)[10]

is a pointer to char[10].

Name: Anonymous 2011-07-21 16:09

>>59
So?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 16:09

And more to the point..

char *q is not the same thing as char (*q)[10].

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 16:10

>>60
The point is that you have a pointer to the *array element* char[10] and not a pointer to the array itself.

Name: Anonymous 2011-07-21 16:11

>>61
I've never said so. But you have.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 16:14

>>63
You said

char (*q)[10] = &a; // a pointer to the array itself

Which is incorrect because

char (*q)[10]

is a pointer to char[10].

Name: Anonymous 2011-07-21 16:16

>>62
the array itself.
The fuck does this even mean?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 16:17

>>65
Well, roughly speaking, according to ANSI/ISO C, an array is an unmodifiable lvalue.

Name: Anonymous 2011-07-21 16:24

>>66
Uhm, so what? This has nothing to do with this discussion, at all.

Name: Anonymous 2011-07-21 16:27

>>67
I was just rebutting someone who clearly doesn't deal with this kind of stuff for a living. Presumably the person doesn't have the mental capacity to do anything beyond general labor jobs.

Name: Anonymous 2011-07-21 16:44

>>66
Anyways. Your misconceptions seem to come from the failure to realize that there basically are 3 "contexts" in which expressions are evaluated in C:
(1) object context
(2) value context
(3) void context

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 16:59

>>69
Huh? I'm not the one that made the following idiotic statement...

char (*q)[10] = &a; // a pointer to the array itself

Besides you fucking mental midget, the object context and the value context bear no real relation to what we are talking about. The fact that you think it might makes you that much dumber

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 17:03

>>69

Equally as dumb is

Anyways. Your misconceptions seem to come from the failure to realize that there basically are 3 "contexts" in which expressions are evaluated

First off, there are only two contexts defined by the standard. The fact that you thin there might be three makes you a fucking dumb nigger. On top of that, those evaluations hold for expressions, expressions statements, and statements.

Name: Anonymous 2011-07-21 17:07

>>70
Right - you're the one who made the following statement:
&a points to the first object in the array named 'a'.
HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA

Unlike yours, my statement is perfectly fine and correct.
And what really bears no relation to the discussion at hand is the fact that expressions with array type are unmodifiable lvalues, BTW.

Name: Anonymous 2011-07-21 17:08

>>71
Which is why I used "s. An eleven y/o would have noticed.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 17:12

>>72
&a points to the first object in the array named 'a'.

&a doesn't point to the array itself.

And what really bears no relation to the discussion at hand is the fact that expressions with array type are unmodifiable lvalues, BTW

Yes it does because you I'm not convinced that you know the difference between an *array* and the *array element* in C.

Name: Anonymous 2011-07-21 17:14

>>74
&a doesn't point to the array itself.
Sorry to bust your bubble, but it does. That's not an opinion; that's a fact.

Get. Over. It.

Name: kodak_gallery_progammer !!kCq+A64Losi56ze 2011-07-21 17:18

>>75
Sorry to bust your bubble, but it does. That's not an opinion; that's a fact.


Are you sure? I just did ptype &a in gdb and I got

type = char (*)[10]

Or in other words, a pointer to char[10]. Nowhere does gdb say that this a pointer to the array itself.

Name: Anonymous 2011-07-21 17:24

>>76

$ cat > proof.c
#include <stdio.h>

int main(void) {
    char a[10] = { 0 };
    char (*p)[10] = &a;

    (*p)[0] = 'x';
    printf("%c\n", a[0]);

    return 0;
}
$ gcc -o proof proof.c && ./proof
x


nuff said

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 17:27

>>77
char (*p)[10] = &a;

This is a pointer to char[10].

(*p)[0] = 'x';

You assign 'x] to char[0].

printf("%c\n", a[0]);

You print the first *array element* of a.

Name: Anonymous 2011-07-21 17:29

>>78
One could basically say, that I've altered the array _itself_.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-07-21 17:33

>>79
One could basically say, that I've altered the array _itself_.


No. You're still confusing an *array* with the *array element* in C. In this case, you are manipulating the *array element* which is part of the *array*. However, at no point and time do you actually manipulate the actual array itself.

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