Deutsch   English   Français   Italiano  
<ve6oiq$2pag3$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.arch
Subject: Re: 80286 protected mode
Date: Wed, 9 Oct 2024 22:20:42 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <ve6oiq$2pag3$1@dont-email.me>
References: <2024Oct6.150415@mips.complang.tuwien.ac.at>
 <memo.20241006163428.19028W@jgd.cix.co.uk>
 <2024Oct7.093314@mips.complang.tuwien.ac.at>
 <7c8e5c75ce0f1e7c95ec3ae4bdbc9249@www.novabbs.org>
 <2024Oct8.092821@mips.complang.tuwien.ac.at> <ve5ek3$2jamt$1@dont-email.me>
 <be506ccef76d682d13205c69c761a086@www.novabbs.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 09 Oct 2024 22:20:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c59c8551724a5b731722e5c93a0179e0";
	logging-data="2927107"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+v9XLya1IgjLpmX5aKeXSB3pxSlqqu/J8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fZxK+ZdSKQJsf0N23BS2K3tsdxQ=
Content-Language: en-GB
In-Reply-To: <be506ccef76d682d13205c69c761a086@www.novabbs.org>
Bytes: 3366

On 09/10/2024 18:28, MitchAlsup1 wrote:
> On Wed, 9 Oct 2024 8:24:34 +0000, David Brown wrote:
> 
>> On 08/10/2024 09:28, Anton Ertl wrote:.
>>
>> When would you ever /need/ to compare pointers to different objects?
>> For almost all C programmers, the answer is "never".  Pretty much the
>> only example people ever give of needing such comparisons is to
>> implement memmove() efficiently - but you don't need to implement
>> memmove(), because it is already in the standard library.  (Standard
>> library implementations don't need to be portable, and can rely on
>> extensions or other compiler-specific features.)
> 
> Somebody has to write memmove() and they want to use C to do it.

They don't have to write it in standard, portable C.  Standard libraries 
will, sometimes, use "magic" - they can be in assembly, or use compiler 
extensions, or target-specific features, or "-fsecret-flag-for-std-lib" 
compiler flags, or implementation-dependent features, or whatever they want.

You will find that most implementations of memmove() are done by 
converting the pointers to a unsigned integer type and comparing those 
values.  The type chosen may be implementation-dependent, or it may be 
"uintptr_t" (even if you are using C90 for your code, the library 
writers can use C99 for theirs).

Such implementations will not be portable to all systems.  They won't 
work on a target that has some kind of "fat" pointers or segmented 
pointers that can't be translated properly to integers.

That's okay, of course.  For targets that have such complications, that 
standard library function will be written in a different way.

The avrlibc library used by gcc for the AVR has its memmove() 
implemented in assembly for speed, as does musl for some architectures.

There are lots of parts of the standard C library that cannot be written 
completely in portable standard C.  (How would you write a function that 
handles files?  You need non-portable OS calls.)  That's why these 
things are in the standard library in the first place.