QUICK QUESTION, ACT NOW
If I typecast a pointer to a different kind of pointer, and incrementz the pointer, will the pointer be incremented by the amount accordiing to the typecast or the real pointer?
Example:
[b]long[/b]* ptr;
([b]char[/b]*) ++ptr;
Which is the result?
A) ptr is increased by sizeof(long) (ie. 4)
B) ptr is increased by sizeof(char) (ie. 1)
thx in advance, kindly /prog/ warriors
ah stupid bold tags
long* ptr;
(char*) ++ptr;
3
Name:
Anonymous
2008-05-21 16:21
Since the cast to char* is applied to the result of ++ptr, then the increment is performed before the cast, and ptr is increased by sizeof(long).
If you did:
char* q = (char*)ptr;
q++;
q would increase by sizeof(char).
4
Name:
Anonymous
2008-05-21 16:24
5
Name:
Anonymous
2008-05-21 16:27
>>3
ok.. but I just want to increase the
long ptr by a
char 's size, rather than the expected 4 bytes
(ps. lol @ actually getting help on /prog/ )
6
Name:
Anonymous
2008-05-21 16:30
DON'T HELP HIM.
7
Name:
Anonymous
2008-05-21 16:31
>>5
Forget it, it's NP-complete.
8
Name:
Anonymous
2008-05-21 17:41
WHAT IS A CHAR* AND HOW IS IT DIFFERENT FROM CHAR
9
Name:
Anonymous
2008-05-21 17:45
>>1
long * ptr;
Bad.
(char *) ++ptr;
Good.
(++ ptr (* char))
Better.
10
Name:
Anonymous
2008-05-21 18:01
>>9
What?
Just tell me how to increase the pointer by only 1 byte instead of 4
11
Name:
Anonymous
2008-05-21 18:15
>>10
You can't be serious.
12
Name:
Anonymous
2008-05-21 18:29
>>10
Why? So that you can generate CPU exceptions via unaligned data access?
13
Name:
Anonymous
2008-05-21 19:00
>>12
Yes. OK NOW TELL ME GO
14
Name:
Anonymous
2008-05-21 20:06
>>13
Unless you are severely retarded, what you're asking is simple enough that you can figure out by yourself.
15
Name:
Anonymous
2008-05-21 23:39
++(char *)ptr
16
Name:
Anonymous
2008-05-21 23:51
Oh well, at least now that
>>15 gave him the answer
1 he might go away.
17
Name:
Anonymous
2008-05-22 4:00
>>15
[Warning] use of cast expressions as lvalues is deprecated.
18
Name:
Anonymous
2008-05-22 4:34
19
Name:
Anonymous
2008-05-22 4:40
>>18
That's what it told me :[
But it did work so thx to whomever posted it... I just want to be able to do it without the annoying
[Warning] .
20
Name:
Anonymous
2008-05-22 4:49
21
Name:
Anonymous
2008-05-22 5:55
a pointer points
22
Name:
Anonymous
2008-05-22 6:32
>>17,19
ptr = (long *)((char *)ptr + 1);
but you should
not do this.
23
Name:
Anonymous
2008-05-22 6:40
24
Name:
Anonymous
2008-05-22 6:42
25
Name:
Anonymous
2008-05-22 6:53
>>23
instead of this:
ptr = (long *)((char *)ptr + 1);
long val = *ptr;
you should do this:
long val = ptr[0] << CHAR_BIT | ptr[1] >> (sizeof(long) - 1) * CHAR_BIT;
26
Name:
Anonymous
2008-05-22 6:53
>>23
Alignment issues you damn retard.
>>25
No, he shouldn't.
Oh right. Well tHANKS FOR HELPING ME GUISE, I AM NOW ON MY WAY TO BECOMING AN EXPERT PROGRAMMER
28
Name:
Anonymous
2008-05-22 7:05
Why don't you just fucking do it and printf the result?
29
Name:
Anonymous
2008-05-22 7:09
>>27
I don't believe we helped you to guise at all. What are you talking about?
30
Name:
Anonymous
2008-05-22 8:47
>>26
No, he shouldn't.
why not? endianness issues are much better than alignment issues!
31
Name:
Anonymous
2008-05-22 8:51
>>26,30
He should use Haskell. It all depends on situation.
32
Name:
Anonymous
2008-05-22 9:28
C is the only language anybody really needs these days.
33
Name:
Anonymous
2008-05-22 9:40
>>32
Sure, if you're a millionare.
34
Name:
Anonymous
2008-05-22 11:48
>>30
Big endian, middle endian and the DeathStation 9000 can go fuck themselves. They´re like starting an array at 1, ½ and π respectivily.
35
Name:
Anonymous
2008-05-22 12:23
lol @ middle-endian
36
Name:
Anonymous
2008-05-22 13:59
wuts an edian?
37
Name:
Anonymous
2008-05-22 14:10
>>36
It's a term describing what side of the egg you eat first: the big end or the little end.
38
Name:
Anonymous
2008-05-22 14:36
>>37
Clever. Now I can finally remember big, middle and small endian.
39
Name:
Anonymous
2008-05-22 15:05
>>38
Bonus points if you know where it comes from, though. No wikipediaing!
40
Name:
Anonymous
2008-05-22 15:19
>>37
u not telling truth i no its sumthing with computa
41
Name:
Anonymous
2008-05-22 15:21
>>40
The term was around long before the invention of computers, you ignorant fuck.
42
Name:
HAX MY ANUS MEME FAN
2008-05-22 16:31
in b4 Gulliver
Believe it or not gentlemen, it is entirely possible to be a well-read man and still appreciate the fine humor of the ``HAX MY ANUS" meme.
43
Name:
Anonymous
2008-05-22 16:36
>>41
i m confoused so it s reely wut u said?
44
Name:
Anonymous
2008-05-22 16:53
>>42
Gulliver from Gulliver's travels? I'm familiar with this story.
45
Name:
Anonymous
2008-05-22 17:21
46
Name:
Anonymous
2008-05-22 18:08
47
Name:
Anonymous
2008-05-22 18:55
>>46
son of a black person
48
Name:
Anonymous
2008-05-22 19:02
typecast my anus
49
Name:
Anonymous
2009-03-06 11:13
re-enabled it after being read in once instead of reading in a big plus All it a day return.
50
Name:
Anonymous
2010-11-26 19:08