| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | indirection |
G'Day Paul,
PE> y = 3 * x;
Turbo C help on "invalid use of pointer" :
Pointers can only be used with addition, subtraction, assignment,
comparison, indirection (*) or arrow (->).
Your source file used a pointer with some other operator.
PE> Come to think of it, I think I remember something about pointers
PE> not being allowed to be divided either. But there is certainly
PE> a reason to want to do that.
PE> middle = (start + end) / 2;
I've tried this with: middle = (char*) ( ( (int)start + (int)end ) \2)
Although (int)middle gives the correct result, middle points somewhere else.
So i thought, ohkay perhaps we're losing the segment(?), try this then...
middle = (char*)MK_FP( FP_SEG(start),FP_OFF((int)start + (int)end ) /2 );
Dammit, it was this simple all the time, and it works :-)
Of course one could use something less professional like..
middle = &start[sizeof(start)/2+1];
PE> I think I remember reading that you had to go:
PE> middle = start + (end - start) / 2;
Yep, this is better,since it does away with the need for sizeof().
How about this then :
Actually it does not compile with ANSI on, but i can't see for the life
of me why, any ideas ?
#include
#include /* everyone should have this by now */
#define P_ADD(ptr1,ptr2) \
(MK_FP ( FP_SEG(ptr1) , FP_OFF((unsigned)ptr1 + (unsigned)ptr2)))
#define P_DIV(ptr1,num) \
(MK_FP ( FP_SEG(ptr1) , FP_OFF((unsigned)ptr1 / num)))
main()
{
char *start = "012*456";
char *end = &start[7];
char *middle;
middle = (char*) P_DIV((char*)P_ADD(start,end),2);
printf("\nThe middle of %s is %c",start,*middle);
return 0;
}
Maybe i can come up with some other ways of making code unreadable :-)
L8r Frank (fadam{at}ozemail.com.au).
___ Blue Wave/DOS v2.21
--- Maximus 3.01
* Origin: The Software Parlour (3:635/544)SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 711/401 409 410 413 SEEN-BY: 711/430 808 809 932 934 712/515 713/888 714/906 800/1 @PATH: 635/544 50/99 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.