Re: [fpc-pascal] values for ThreadSetPriority
On 11 Feb 2010, at 01:10, Seth Grover wrote: http://www.hu.freepascal.org/docs-html/rtl/system/threadsetpriority.html says that it takes for a priority values from -15 to 15. The comment to the right of the declaration says that "0" is normal. Are these numbers like nice's, where negative numbers are more favorable (higher priority) and positive numbers are less favorable (lower priority)? This function is currently only hooked up for Windows and is mapped directly to the "WinThreadSetPriority" win32 api function (which directly takes these inputs). Whatever MSDN defines as the meaning of that parameter is what it will also mean on other platforms, when/if it's hooked up there. Also, to further confuse my mind, I found this: http://community.freepascal.org:1/docs-html/rtl/classes/tthreadpriority.html which has some enumerations. How do those come into play? Are those just for TThread descendents? Yes. I'm just trying to find the correct cross-platform approach for changing thread priority of threads started with BeginThread. In theory the function to use would be system.threadsetpriority, but in practice this will only work on Windows currently. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Pointers
What is the difference between A* and B*? regards, Rainer type tchararr = array[ 0..999 ] of char; pchararr = ^tchararr; http_obj = object pdata: pchararr; header_anz: longint; content_anz : longint; end; var http : http_obj; ppp : pointer; // This works for me A* ppp := http.pdata; ppp := ppp + http.header_anz; // This is not working B* ppp := http.pdata + http.header_anz; write( 'IP-Adress = ' + parse_ip( ppp , http.content_anz ) ); ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
So you're allowed add an integer to an untyped pointer?! Wow! Usually if you add 1 to a pointer of type t, then sizeof(t) gets added to the value of the pointer. So if p points at an array of byte, p+1 would point at the next element of the array, 1 byte after p. But if p points at an array of LongInt, then the next element is 4 bytes on from p, so adding 1 to p increases p by 4. So what would sizeof(pointer^) be? To me, adding an integer to an untyped pointer feels undefined (i.e. I haven't studied the spec for it but I wouldn't have expected the compiler to do anything sensible with it) because what pointer points to is undefined and sizeof(something undefined) is not defined. So I haven't tried that myself. From your code, I'm guessing that adding 1 to an untyped pointer adds 1 to the address. So ppp + http.header_anz would be http.header_anz bytes after ppp. But http.pdata + http.header_anz means to add http.header_anz to a variable of type pointer to tchararr. That means, imagine http.pdata is pointing to an array[0..lots] of tcharrarr, find the address of element http.header_anz of that array. Now, tcharrarr is 1000 bytes long, so I would expect http.pdata + http.header_anz to be 1000*http.header_anz bytes after http.pdata. Is that what you are seeing? FP On 11/02/2010 15:38, Rainer Stratmann wrote: What is the difference between A* and B*? regards, Rainer type tchararr = array[ 0..999 ] of char; pchararr = ^tchararr; http_obj = object pdata: pchararr; header_anz: longint; content_anz : longint; end; var http : http_obj; ppp : pointer; // This works for me A* ppp := http.pdata; ppp := ppp + http.header_anz; // This is not working B* ppp := http.pdata + http.header_anz; write( 'IP-Adress = ' + parse_ip( ppp , http.content_anz ) ); ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
I thought that adding something to a pointer always adds 1 sizeof(byte) to it. So if something is added to a pointer the compiler looks the sizeof the (typed) pointer points to? Ok, that makes some sense, but I did not know it before. In the past with the turbopascal compiler and other always sizeof byte was added. Thank you and regards, Rainer Am Thursday 11 February 2010 17:36:04 schrieb Frank Peelo: > So you're allowed add an integer to an untyped pointer?! > > Wow! > > Usually if you add 1 to a pointer of type t, then sizeof(t) gets added > to the value of the pointer. So if p points at an array of byte, p+1 > would point at the next element of the array, 1 byte after p. But if p > points at an array of LongInt, then the next element is 4 bytes on from > p, so adding 1 to p increases p by 4. So what would sizeof(pointer^) be? > > To me, adding an integer to an untyped pointer feels undefined (i.e. I > haven't studied the spec for it but I wouldn't have expected the > compiler to do anything sensible with it) because what pointer points to > is undefined and sizeof(something undefined) is not defined. So I > haven't tried that myself. > > From your code, I'm guessing that adding 1 to an untyped pointer adds 1 > to the address. So ppp + http.header_anz would be http.header_anz bytes > after ppp. > > But http.pdata + http.header_anz means to add http.header_anz to a > variable of type pointer to tchararr. That means, imagine http.pdata is > pointing to an array[0..lots] of tcharrarr, find the address of element > http.header_anz of that array. Now, tcharrarr is 1000 bytes long, so I > would expect http.pdata + http.header_anz to be 1000*http.header_anz > bytes after http.pdata. > > Is that what you are seeing? I did not test it, but I think you are right. > FP > > On 11/02/2010 15:38, Rainer Stratmann wrote: > > What is the difference between A* and B*? > > regards, Rainer > > > > > > type > > tchararr = array[ 0..999 ] of char; > > pchararr = ^tchararr; > > > > http_obj = object > > pdata: pchararr; > > header_anz: longint; > > content_anz : longint; > > end; > > > > var > > http : http_obj; > > ppp : pointer; > > > > > > // This works for me A* > > ppp := http.pdata; > > ppp := ppp + http.header_anz; > > // This is not working B* > > ppp := http.pdata + http.header_anz; > > > > > > write( 'IP-Adress = ' + parse_ip( ppp , http.content_anz ) ); > > ___ > > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
Rainer Stratmann wrote: Ok, that makes some sense, but I did not know it before. In the past with the turbopascal compiler and other always sizeof byte was added. The behavior is dependent on the {$T+} (typed pointers) mode. Micha ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
On 11 Feb 2010, at 18:17, Rainer Stratmann wrote: In the past with the turbopascal compiler and other always sizeof byte was added. That is not true. This program prints "2" when compiled under Turbo Pascal: {$t-} type pw = ^word; var w: pw; begin w:=nil; inc(w); writeln(longint(w)); end. (and the result does not depend on {$t+} or {$t-}; that only influences whether e.g. @wordvar has the type "^word" or plain "pointer"). Furthermore, Turbo Pascal did not support performing pointer arithmetic using anything else but inc() and dec() (so things like "ppp := ppp + http.header_anz" or "w:=w+1" would not compile under TP), except for pchar variables (in which case the base value is sizeof(char), since that's what a pchar points to). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
Am Thursday 11 February 2010 21:07:17 schrieb Jonas Maebe: > On 11 Feb 2010, at 18:17, Rainer Stratmann wrote: > > In the past with the turbopascal compiler and other always sizeof > > byte was > > added. > > That is not true. This program prints "2" when compiled under Turbo > Pascal: Ok, sorry I don't remember exactly, but it feels like that tp did this. Is there a site how to deal with pointers? > {$t-} > > type >pw = ^word; > var >w: pw; > begin >w:=nil; >inc(w); >writeln(longint(w)); > end. > > (and the result does not depend on {$t+} or {$t-}; that only > influences whether e.g. @wordvar has the type "^word" or plain > "pointer"). > > Furthermore, Turbo Pascal did not support performing pointer > arithmetic using anything else but inc() and dec() (so things like > "ppp := ppp + http.header_anz" or "w:=w+1" would not compile under > TP), except for pchar variables (in which case the base value is > sizeof(char), since that's what a pchar points to). > > > Jonas > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
At 12:07 PM 2/11/2010, Jonas Maebe wrote: On 11 Feb 2010, at 18:17, Rainer Stratmann wrote: In the past with the turbopascal compiler and other always sizeof byte was added. That is not true. This program prints "2" when compiled under Turbo Pascal: I am fairly certain that he confuses this with the special case of applying sizeof() to a string type, where you always get one byte more (the preceding length byte) than the string type has been defined, for example SizeOf (String [80]) will return 81, 80 bytes reserved for the contents plus the length byte... Ralf ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
Am Thursday 11 February 2010 21:24:03 schrieb Ralf A. Quint: > At 12:07 PM 2/11/2010, Jonas Maebe wrote: > >On 11 Feb 2010, at 18:17, Rainer Stratmann wrote: > >>In the past with the turbopascal compiler and other always sizeof > >>byte was > >>added. > > > >That is not true. This program prints "2" when compiled under Turbo > >Pascal: > > I am fairly certain that he confuses this with the special case of > applying sizeof() to a string type, where you always get one byte > more (the preceding length byte) than the string type has been > defined, for example SizeOf (String [80]) will return 81, 80 bytes > reserved for the contents plus the length byte... > > Ralf How can I have access to position 4 of a pointer? var p : pbyte; c : char; s : ansistring; x : longint; ... s := 'Hello'; p := @s; x := 4; // 4th position c := [p+x]^ ??? how to get access to the 'o' ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
At 12:53 PM 2/11/2010, Rainer Stratmann wrote: > I am fairly certain that he confuses this with the special case of > applying sizeof() to a string type, where you always get one byte > more (the preceding length byte) than the string type has been > defined, for example SizeOf (String [80]) will return 81, 80 bytes > reserved for the contents plus the length byte... > > Ralf How can I have access to position 4 of a pointer? By using Pascal and not C! var p : Pointer; c : char; s : ansistring; x : longint; begin s := 'Hello'; p := @s; x := 5; // 5th position c := Char (ANSIString (p^)[x]); WriteLn ('Character No.',x,' is ',c); end. Ralf ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
On Thu 11 Feb 2010, Rainer Stratmann wrote: > How can I have access to position 4 of a pointer? > > var > p : pbyte; > c : char; > s : ansistring; > x : longint; > > s := 'Hello'; > p := @s; > x := 4; // 4th position > c := [p+x]^ ??? how to get access to the 'o' c := (p+x)^; // why would someone use square brackets for that? Of course, if you are actually working with a string, there is no need to use pointers. c := s[5]; // remember strings are 1-indexed You can also increment... inc (p, 4); c := p^; I might make a second pointer, q, and increment that, so p can stay in place. ~David. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pointers
On Thu, 11 Feb 2010 21:53:59 +0100 Rainer Stratmann wrote: > Am Thursday 11 February 2010 21:24:03 schrieb Ralf A. Quint: > > At 12:07 PM 2/11/2010, Jonas Maebe wrote: > > >On 11 Feb 2010, at 18:17, Rainer Stratmann wrote: > > >>In the past with the turbopascal compiler and other always sizeof > > >>byte was > > >>added. > > > > > >That is not true. This program prints "2" when compiled under Turbo > > >Pascal: > > > > I am fairly certain that he confuses this with the special case of > > applying sizeof() to a string type, where you always get one byte > > more (the preceding length byte) than the string type has been > > defined, for example SizeOf (String [80]) will return 81, 80 bytes > > reserved for the contents plus the length byte... > > > > Ralf > > How can I have access to position 4 of a pointer? > > var > p : pbyte; > c : char; > s : ansistring; > x : longint; > > ... > > s := 'Hello'; > p := @s; Now p is an PAnsiString. Maybe you meant: p:=PByte(s); > x := 4; // 4th position > > c := [p+x]^ ??? how to get access to the 'o' c:=chr(p[x]); But normally you use PChar: var p: PChar; ... p:=s; c:=p[x]; Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal