Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #31974 > unrolled thread

addon functions

Started byHul Tytus <ht@panix.com>
First post2023-08-01 21:21 +0000
Last post2023-08-02 18:38 +0200
Articles 5 — 4 participants

Back to article view | Back to comp.arch.embedded


Contents

  addon functions Hul Tytus <ht@panix.com> - 2023-08-01 21:21 +0000
    Re: addon functions Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2023-08-01 23:44 +0200
    Re: addon functions Grant Edwards <invalid@invalid.invalid> - 2023-08-01 22:26 +0000
      Re: addon functions Hul Tytus <ht@panix.com> - 2023-08-03 16:52 +0000
    Re: addon functions David Brown <david.brown@hesbynett.no> - 2023-08-02 18:38 +0200

#31974 — addon functions

FromHul Tytus <ht@panix.com>
Date2023-08-01 21:21 +0000
Subjectaddon functions
Message-ID<uabt18$qtu$1@reader2.panix.com>
Lewin Edwards in his dosfs file system uses the ldiv() functions shown below:
	sector = ldiv(offset, SECTOR_SIZE).quot  and
	offset = ldiv(offset, SECTOR_SIZE).rem
Anybody know how this is declared or, maybe, defined?

Hul

[toc] | [next] | [standalone]


#31975

FromHans-Bernhard Bröker <HBBroeker@t-online.de>
Date2023-08-01 23:44 +0200
Message-ID<kitcm3Fjvv7U1@mid.dfncis.de>
In reply to#31974
Am 01.08.2023 um 23:21 schrieb Hul Tytus:
> Lewin Edwards in his dosfs file system uses the ldiv() functions shown below:
> 	sector = ldiv(offset, SECTOR_SIZE).quot  and
> 	offset = ldiv(offset, SECTOR_SIZE).rem
> Anybody know how this is declared or, maybe, defined?

Seriously?  Does every C compiler you use come without a manual?

How else could you possibly find it hard to discover the declaration and 
semantics of a 33+ years old C standard library function like that?

[toc] | [prev] | [next] | [standalone]


#31976

FromGrant Edwards <invalid@invalid.invalid>
Date2023-08-01 22:26 +0000
Message-ID<uac0ri$6n0$1@reader2.panix.com>
In reply to#31974
On 2023-08-01, Hul Tytus <ht@panix.com> wrote:
> Lewin Edwards in his dosfs file system uses the ldiv() functions shown below:
> 	sector = ldiv(offset, SECTOR_SIZE).quot  and
> 	offset = ldiv(offset, SECTOR_SIZE).rem
> Anybody know how this is declared or, maybe, defined?

$ man ldiv

------------------------------------------------------------------------------
div(3)                     Library Functions Manual                     div(3)

NAME
       div,  ldiv, lldiv, imaxdiv - compute quotient and remainder of an inte‐
       ger division

LIBRARY
       Standard C library (libc, -lc)

SYNOPSIS
       #include <stdlib.h>

       div_t div(int numerator, int denominator);
       ldiv_t ldiv(long numerator, long denominator);
       lldiv_t lldiv(long long numerator, long long denominator);

       #include <inttypes.h>

       imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator);


[...]

[toc] | [prev] | [next] | [standalone]


#31978

FromHul Tytus <ht@panix.com>
Date2023-08-03 16:52 +0000
Message-ID<uaglvp$id9$1@reader2.panix.com>
In reply to#31976
Thanks Grant. I'd never seen those before and assumed they were Lewin's creation.

Hul

Grant Edwards <invalid@invalid.invalid> wrote:
> On 2023-08-01, Hul Tytus <ht@panix.com> wrote:
> > Lewin Edwards in his dosfs file system uses the ldiv() functions shown below:
> >       sector = ldiv(offset, SECTOR_SIZE).quot  and
> >       offset = ldiv(offset, SECTOR_SIZE).rem
> > Anybody know how this is declared or, maybe, defined?

> $ man ldiv

> ------------------------------------------------------------------------------
> div(3)                     Library Functions Manual                     div(3)

> NAME
>        div,  ldiv, lldiv, imaxdiv - compute quotient and remainder of an inte???
>        ger division

> LIBRARY
>        Standard C library (libc, -lc)

> SYNOPSIS
>        #include <stdlib.h>

>        div_t div(int numerator, int denominator);
>        ldiv_t ldiv(long numerator, long denominator);
>        lldiv_t lldiv(long long numerator, long long denominator);

>        #include <inttypes.h>

>        imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator);


> [...]

[toc] | [prev] | [next] | [standalone]


#31977

FromDavid Brown <david.brown@hesbynett.no>
Date2023-08-02 18:38 +0200
Message-ID<uae0ph$5oj9$1@dont-email.me>
In reply to#31974
On 01/08/2023 23:21, Hul Tytus wrote:
> Lewin Edwards in his dosfs file system uses the ldiv() functions shown below:
> 	sector = ldiv(offset, SECTOR_SIZE).quot  and
> 	offset = ldiv(offset, SECTOR_SIZE).rem
> Anybody know how this is declared or, maybe, defined?
> 
> Hul
> 

It's a standard C library function.  You can see its definition in the C 
standards (draft versions of all modern C standards are freely available 
online).  A good reference for C is the "cppreference" site, with the 
exact page here being:

<https://en.cppreference.com/w/c/numeric/math/div>

The "div" functions are almost never used these days - any decent 
compiler will do as good or better when the code is expressed simply as:

	sector = offset / SECTOR_SIZE;
	offset = offset % SECTOR_SIZE;

But the "div" functions made sense with older and poorer compilers.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.arch.embedded


csiph-web