Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

There *__is* no such thing as a civil engineer.


devel / comp.lang.c / Verbose assert

SubjectAuthor
* Verbose assertMehdi Amini
+- Re: Verbose assertStefan Ram
+* Re: Verbose assertStefan Ram
|`* Re: Verbose assertMehdi Amini
| `* Re: Verbose assertStefan Ram
|  `* Re: Verbose assertMehdi Amini
|   `- Re: Verbose assertJames Kuyper
+* Re: Verbose assertMalcolm McLean
|`* Re: Verbose assertScott Lurndal
| +* Re: Verbose assertBonita Montero
| |`* Re: Verbose assertScott Lurndal
| | `* Re: Verbose assertBonita Montero
| |  `* Re: Verbose assertÖö Tiib
| |   `* Re: Verbose assertBonita Montero
| |    +* Re: Verbose assertScott Lurndal
| |    |+- Re: Verbose assertMalcolm McLean
| |    |`- Re: Verbose assertBonita Montero
| |    `* Re: Verbose assertKaz Kylheku
| |     +- Re: Verbose assertScott Lurndal
| |     `- Re: Verbose assertBonita Montero
| `* Re: Verbose assertMehdi Amini
|  +* Re: Verbose assertBen Bacarisse
|  |+* Re: Verbose assertBen Bacarisse
|  ||`* Re: Verbose assertMehdi Amini
|  || +- Re: Verbose assertKeith Thompson
|  || `* Re: Verbose assertTim Rentsch
|  ||  `* Re: Verbose assertKeith Thompson
|  ||   `* Re: Verbose assertTim Rentsch
|  ||    `* Re: Verbose assertKaz Kylheku
|  ||     `- Re: Verbose assertTim Rentsch
|  |`- Re: Verbose assertTim Rentsch
|  `- Re: Verbose assertScott Lurndal
`* Re: Verbose assertJorgen Grahn
 `* Re: Verbose assertKenny McCormack
  +- Re: Verbose assertÖö Tiib
  `* Re: Verbose assertScott Lurndal
   `* Re: Verbose assertKenny McCormack
    +- Re: Verbose assertScott Lurndal
    `* Re: Verbose assertJames Kuyper
     `* Some weirdos who can't follow directions (Was: Verbose assert)Kenny McCormack
      +* Re: Some weirdos who can't follow directions (Was: Verbose assert)Malcolm McLean
      |`* Obedience (Was: Some weirdos who can't follow directions (Was: Verbose assert))Kenny McCormack
      | `* Re: ObedienceOtto J. Makela
      |  `- Re: ObedienceKenny McCormack
      `- Re: Some weirdos who can't follow directions (Was: Verbose assert)james...@alumni.caltech.edu

Pages:12
Verbose assert

<suq3j4$2r5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20486&group=comp.lang.c#20486

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: atorr...@gmail.com (Mehdi Amini)
Newsgroups: comp.lang.c
Subject: Verbose assert
Date: Sat, 19 Feb 2022 10:13:46 +0330
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <suq3j4$2r5$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 19 Feb 2022 06:43:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="06b4b7166310aed4adf94d95602471a7";
logging-data="2917"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195Q3JQyrnKlNAm2SVWVKcqjKrjX5CNce0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:/L0RhbSkSMRkxj26MpXxj5PHtoI=
Content-Language: en-US
 by: Mehdi Amini - Sat, 19 Feb 2022 06:43 UTC

Hi,

Considering usage of "assert" , I want a more informative output from
it. Consider:

// Code:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{ int b=3;
int a=2;

assert(a==b);

return 0;
}

Output of gcc:
verbose_assert.out: verbose_assert.c:10: main: Assertion `a==b' failed.
Aborted (core dumped)

Output of clang:
verbose_assert.out: verbose_assert.c:10: int main(void): Assertion
`a==b' failed.
Aborted (core dumped)

I want more details in compiler's output , like for example:
a is 2
b is 3

Re: Verbose assert

<assert-20220219084844@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20487&group=comp.lang.c#20487

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Supersedes: <assert-20220219084524@ram.dialup.fu-berlin.de>
Date: 19 Feb 2022 07:50:23 GMT
Organization: Stefan Ram
Lines: 28
Expires: 1 Apr 2022 11:59:58 GMT
Message-ID: <assert-20220219084844@ram.dialup.fu-berlin.de>
References: <suq3j4$2r5$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de lV6ulOsYwZrO3brGp1TRtQqs5ytxBIEfpLmJUHHyTw1TMp
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 19 Feb 2022 07:50 UTC

Supersedes: <assert-20220219084524@ram.dialup.fu-berlin.de>
[changed one "assert_equal" to "ASSERT_EQUAL"]

Mehdi Amini <atorrses@gmail.com> writes:
>I want more details in compiler's output , like for example:
>a is 2
>b is 3

#include <stdio.h>

#ifdef NDEBUG
#define ASSERT_EQUAL(a,b) ((void)0)
#else
#define ASSERT_FORMAT(x) _Generic(x,int:"%d",default:"?")
#define ASSERT_PRINT(x) \
{fprintf(stderr,#x " is ");\
fprintf(stderr,ASSERT_FORMAT(x),x);\
fprintf(stderr,"\n");}
#define ASSERT_FAILURE(a,b) {ASSERT_PRINT(a);ASSERT_PRINT(b);}
#define ASSERT_EQUAL_VARS(a,b) {if(!(a==b))ASSERT_FAILURE(a,b)}while(0)
#endif

int main( void )
{ int const a = 2;
int const b = 3;
ASSERT_EQUAL_VARS(a,b); }

Re: Verbose assert

<assert-20220219085441@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20488&group=comp.lang.c#20488

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Supersedes: <assert-20220219084844@ram.dialup.fu-berlin.de>
Date: 19 Feb 2022 07:56:11 GMT
Organization: Stefan Ram
Lines: 31
Expires: 1 Apr 2022 11:59:58 GMT
Message-ID: <assert-20220219085441@ram.dialup.fu-berlin.de>
References: <suq3j4$2r5$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 9Luxjl0r6M8vUONoXOO59QsKO+JoHurhe9pYHYmoRUukp4
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 19 Feb 2022 07:56 UTC

Supersedes: <assert-20220219084844@ram.dialup.fu-berlin.de>
[changed one "ASSERT_EQUAL" to "ASSERT_EQUAL_VARS"]

Supersedes: <assert-20220219084524@ram.dialup.fu-berlin.de>
[changed one "assert_equal" to "ASSERT_EQUAL"]

Mehdi Amini <atorrses@gmail.com> writes:
>I want more details in compiler's output , like for example:
>a is 2
>b is 3

#include <stdio.h>

#ifdef NDEBUG
#define ASSERT_EQUAL_VARS(a,b) ((void)0)
#else
#define ASSERT_FORMAT(x) _Generic(x,int:"%d",default:"?")
#define ASSERT_PRINT(x) \
{fprintf(stderr,#x " is ");\
fprintf(stderr,ASSERT_FORMAT(x),x);\
fprintf(stderr,"\n");}
#define ASSERT_FAILURE(a,b) {ASSERT_PRINT(a);ASSERT_PRINT(b);}
#define ASSERT_EQUAL_VARS(a,b) {if(!(a==b))ASSERT_FAILURE(a,b)}while(0)
#endif

int main( void )
{ int const a = 2;
int const b = 3;
ASSERT_EQUAL_VARS(a,b); }

Re: Verbose assert

<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20489&group=comp.lang.c#20489

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a1c:f705:0:b0:37d:f2e5:d8ec with SMTP id v5-20020a1cf705000000b0037df2e5d8ecmr14477658wmh.21.1645273801253;
Sat, 19 Feb 2022 04:30:01 -0800 (PST)
X-Received: by 2002:a05:622a:1441:b0:2dc:e1cd:4a99 with SMTP id
v1-20020a05622a144100b002dce1cd4a99mr10723448qtx.34.1645273800797; Sat, 19
Feb 2022 04:30:00 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 19 Feb 2022 04:30:00 -0800 (PST)
In-Reply-To: <suq3j4$2r5$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:157e:13ad:a74e:6815;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:157e:13ad:a74e:6815
References: <suq3j4$2r5$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
Subject: Re: Verbose assert
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Sat, 19 Feb 2022 12:30:01 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Sat, 19 Feb 2022 12:30 UTC

On Saturday, 19 February 2022 at 06:44:18 UTC, Mehdi Amini Valashani son of Bahram wrote:
> Hi,
>
> Considering usage of "assert" , I want a more informative output from
> it. Consider:
>
> // Code:
> #include <assert.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {
> int b=3;
> int a=2;
>
> assert(a==b);
>
> return 0;
> }
>
> Output of gcc:
> verbose_assert.out: verbose_assert.c:10: main: Assertion `a==b' failed.
> Aborted (core dumped)
>
> Output of clang:
> verbose_assert.out: verbose_assert.c:10: int main(void): Assertion
> `a==b' failed.
> Aborted (core dumped)
>
> I want more details in compiler's output , like for example:
> a is 2
> b is 3
>
The onyl way to do this would be to patch the compiler itself. You can
easily write your own assert() macro, but the expression a == b just resolves
to either 1 or 0 within the macro. You can stringify it, but you can't link
the string component "a" to the variable a.

Re: Verbose assert

<Gu8QJ.14770$XFM9.1016@fx18.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20490&group=comp.lang.c#20490

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Verbose assert
Newsgroups: comp.lang.c
References: <suq3j4$2r5$1@dont-email.me> <bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
Lines: 52
Message-ID: <Gu8QJ.14770$XFM9.1016@fx18.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 19 Feb 2022 16:00:38 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 19 Feb 2022 16:00:38 GMT
X-Received-Bytes: 2221
 by: Scott Lurndal - Sat, 19 Feb 2022 16:00 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>On Saturday, 19 February 2022 at 06:44:18 UTC, Mehdi Amini Valashani son of Bahram wrote:
>> Hi,
>>
>> Considering usage of "assert" , I want a more informative output from
>> it. Consider:
>>
>> // Code:
>> #include <assert.h>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main(void)
>> {
>> int b=3;
>> int a=2;
>>
>> assert(a==b);
>>
>> return 0;
>> }
>>
>> Output of gcc:
>> verbose_assert.out: verbose_assert.c:10: main: Assertion `a==b' failed.
>> Aborted (core dumped)
>>
>> Output of clang:
>> verbose_assert.out: verbose_assert.c:10: int main(void): Assertion
>> `a==b' failed.
>> Aborted (core dumped)
>>
>> I want more details in compiler's output , like for example:
>> a is 2
>> b is 3
>>
>The onyl way to do this would be to patch the compiler itself. You can
>easily write your own assert() macro, but the expression a == b just resolves
>to either 1 or 0 within the macro. You can stringify it, but you can't link
>the string component "a" to the variable a.

void my_assert_msg(const char* filep, int lineno,
const char* conditionp, const char* fmtp="", ...);

#define MY_ASSERT(condition, ...) \
do if (unlikely(!(condition))) { \
my_assert_msg(__FILE__,__LINE__, #condition, ## __VA_ARGS__); \
abort(); \
} while(0)

#ifndef ASSERT
# define ASSERT MY_ASSERT
#endif

Re: Verbose assert

<sur59v$1tv$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20491&group=comp.lang.c#20491

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Sat, 19 Feb 2022 17:19:09 +0100
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <sur59v$1tv$1@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 19 Feb 2022 16:19:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6fbce316aadc48ea9c975e4725b4d695";
logging-data="1983"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4QFvYBQ86JBZaNMCM2NgQb1yF6970AS4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:iwCfGB48YJa4cXlJ1ffcu2dGo+Q=
In-Reply-To: <Gu8QJ.14770$XFM9.1016@fx18.iad>
Content-Language: de-DE
 by: Bonita Montero - Sat, 19 Feb 2022 16:19 UTC

Am 19.02.2022 um 17:00 schrieb Scott Lurndal:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>> On Saturday, 19 February 2022 at 06:44:18 UTC, Mehdi Amini Valashani son of Bahram wrote:
>>> Hi,
>>>
>>> Considering usage of "assert" , I want a more informative output from
>>> it. Consider:
>>>
>>> // Code:
>>> #include <assert.h>
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>>
>>> int main(void)
>>> {
>>> int b=3;
>>> int a=2;
>>>
>>> assert(a==b);
>>>
>>> return 0;
>>> }
>>>
>>> Output of gcc:
>>> verbose_assert.out: verbose_assert.c:10: main: Assertion `a==b' failed.
>>> Aborted (core dumped)
>>>
>>> Output of clang:
>>> verbose_assert.out: verbose_assert.c:10: int main(void): Assertion
>>> `a==b' failed.
>>> Aborted (core dumped)
>>>
>>> I want more details in compiler's output , like for example:
>>> a is 2
>>> b is 3
>>>
>> The onyl way to do this would be to patch the compiler itself. You can
>> easily write your own assert() macro, but the expression a == b just resolves
>> to either 1 or 0 within the macro. You can stringify it, but you can't link
>> the string component "a" to the variable a.
>
> void my_assert_msg(const char* filep, int lineno,
> const char* conditionp, const char* fmtp="", ...);
>
> #define MY_ASSERT(condition, ...) \
> do if (unlikely(!(condition))) { \

Lol, "unlikely", if the performance of debugging-code would be an issue.

> my_assert_msg(__FILE__,__LINE__, #condition, ## __VA_ARGS__); \
> abort(); \
> } while(0)
>
> #ifndef ASSERT
> # define ASSERT MY_ASSERT
> #endif

Re: Verbose assert

<j29QJ.14638$LRj9.11090@fx29.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20492&group=comp.lang.c#20492

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx29.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Verbose assert
Newsgroups: comp.lang.c
References: <suq3j4$2r5$1@dont-email.me> <bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com> <Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me>
Lines: 15
Message-ID: <j29QJ.14638$LRj9.11090@fx29.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 19 Feb 2022 16:38:39 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 19 Feb 2022 16:38:39 GMT
X-Received-Bytes: 1320
 by: Scott Lurndal - Sat, 19 Feb 2022 16:38 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 19.02.2022 um 17:00 schrieb Scott Lurndal:

>>
>> void my_assert_msg(const char* filep, int lineno,
>> const char* conditionp, const char* fmtp="", ...);
>>
>> #define MY_ASSERT(condition, ...) \
>> do if (unlikely(!(condition))) { \
>
>Lol, "unlikely", if the performance of debugging-code would be an issue.

Indeed, it's quite important from a performance standpoint
to help the compiler generate branch-predictor friendly code. Not
quite sure why you think it is funny.

Re: Verbose assert

<surf3h$fv0$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20493&group=comp.lang.c#20493

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Sat, 19 Feb 2022 20:06:23 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <surf3h$fv0$2@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me>
<j29QJ.14638$LRj9.11090@fx29.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 19 Feb 2022 19:06:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6fbce316aadc48ea9c975e4725b4d695";
logging-data="16352"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19P/AvSEiR3+RX1W/Ks35Ms+kPaKc7Olf4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:aBg23WJkc448fP2aAUskuaa6xN4=
In-Reply-To: <j29QJ.14638$LRj9.11090@fx29.iad>
Content-Language: de-DE
 by: Bonita Montero - Sat, 19 Feb 2022 19:06 UTC

Am 19.02.2022 um 17:38 schrieb Scott Lurndal:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 19.02.2022 um 17:00 schrieb Scott Lurndal:
>
>>>
>>> void my_assert_msg(const char* filep, int lineno,
>>> const char* conditionp, const char* fmtp="", ...);
>>>
>>> #define MY_ASSERT(condition, ...) \
>>> do if (unlikely(!(condition))) { \
>>
>> Lol, "unlikely", if the performance of debugging-code would be an issue.
>
> Indeed, it's quite important from a performance standpoint
> to help the compiler generate branch-predictor friendly code.

No one cares for the performance of debugging-code. And when
you compile a perfomant release the debugging-code is stripped.

Re: Verbose assert

<susovh$qvj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20494&group=comp.lang.c#20494

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: atorr...@gmail.com (Mehdi Amini)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Sun, 20 Feb 2022 10:31:03 +0330
Organization: A noiseless patient Spider
Lines: 101
Message-ID: <susovh$qvj$1@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 20 Feb 2022 07:01:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1221a5032f5b3896194728b266d37299";
logging-data="27635"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IgTfi29wY1R0yHQzRO+MSH2EdwoWO9TA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:4WoDb2XlxbBb1RCukAycqbCZV5I=
In-Reply-To: <Gu8QJ.14770$XFM9.1016@fx18.iad>
Content-Language: en-US
 by: Mehdi Amini - Sun, 20 Feb 2022 07:01 UTC

On 2/19/22 19:30, Scott Lurndal wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>> On Saturday, 19 February 2022 at 06:44:18 UTC, Mehdi Amini Valashani son of Bahram wrote:
>>> Hi,
>>>
>>> Considering usage of "assert" , I want a more informative output from
>>> it. Consider:
>>>
>>> // Code:
>>> #include <assert.h>
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>>
>>> int main(void)
>>> {
>>> int b=3;
>>> int a=2;
>>>
>>> assert(a==b);
>>>
>>> return 0;
>>> }
>>>
>>> Output of gcc:
>>> verbose_assert.out: verbose_assert.c:10: main: Assertion `a==b' failed.
>>> Aborted (core dumped)
>>>
>>> Output of clang:
>>> verbose_assert.out: verbose_assert.c:10: int main(void): Assertion
>>> `a==b' failed.
>>> Aborted (core dumped)
>>>
>>> I want more details in compiler's output , like for example:
>>> a is 2
>>> b is 3
>>>
>> The onyl way to do this would be to patch the compiler itself. You can
>> easily write your own assert() macro, but the expression a == b just resolves
>> to either 1 or 0 within the macro. You can stringify it, but you can't link
>> the string component "a" to the variable a.
>
> void my_assert_msg(const char* filep, int lineno,
> const char* conditionp, const char* fmtp="", ...);
>
> #define MY_ASSERT(condition, ...) \
> do if (unlikely(!(condition))) { \
> my_assert_msg(__FILE__,__LINE__, #condition, ## __VA_ARGS__); \
> abort(); \
> } while(0)
>
> #ifndef ASSERT
> # define ASSERT MY_ASSERT
> #endif

Complete code :
#include <stdio.h>
#include <stdlib.h>

void my_assert_msg(const char* filep, int lineno,
const char* conditionp, const char* fmtp="", ...);

#define MY_ASSERT(condition, ...) \
do if (unlikely(!(condition))) { \
my_assert_msg(__FILE__,__LINE__, #condition, ## __VA_ARGS__); \
abort(); \
} while(0)

#ifndef ASSERT
# define ASSERT MY_ASSERT
#endif

int main(void)
{ int a,b;
a=2;
b=3;

MY_ASSERT(a==b);

return 0;
}

I get this :

$ clang -Wall -Wextra -pedantic -std=c11 custom_assert2.c -o
custom_assert2.out
custom_assert2.c:6:61: error: C does not support default arguments
const char* conditionp, const char* fmtp="", ...);
^~~
custom_assert2.c:10:53: warning: token pasting of ',' and __VA_ARGS__ is
a GNU extension [-Wgnu-zero-variadic-macro-arguments]
my_assert_msg(__FILE__,__LINE__, #condition, ## __VA_ARGS__); \
^
custom_assert2.c:24:5: warning: implicit declaration of function
'unlikely' is invalid in C99 [-Wimplicit-function-declaration]
MY_ASSERT(a==b);
^
custom_assert2.c:9:11: note: expanded from macro 'MY_ASSERT'
do if (unlikely(!(condition))) { \
^
2 warnings and 1 error generated.

Re: Verbose assert

<suspbj$sip$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20495&group=comp.lang.c#20495

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: atorr...@gmail.com (Mehdi Amini)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Sun, 20 Feb 2022 10:37:30 +0330
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <suspbj$sip$1@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<assert-20220219085441@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 20 Feb 2022 07:07:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1221a5032f5b3896194728b266d37299";
logging-data="29273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7OKc619NqSdd036JTWEpZ3xfWqG0OTtY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:Etc47tgubJ4gCMIukC0WNgSUs+s=
In-Reply-To: <assert-20220219085441@ram.dialup.fu-berlin.de>
Content-Language: en-US
 by: Mehdi Amini - Sun, 20 Feb 2022 07:07 UTC

On 2/19/22 11:26, Stefan Ram wrote:
> Supersedes: <assert-20220219084844@ram.dialup.fu-berlin.de>
> [changed one "ASSERT_EQUAL" to "ASSERT_EQUAL_VARS"]
>
> Supersedes: <assert-20220219084524@ram.dialup.fu-berlin.de>
> [changed one "assert_equal" to "ASSERT_EQUAL"]
>
> Mehdi Amini <atorrses@gmail.com> writes:
>> I want more details in compiler's output , like for example:
>> a is 2
>> b is 3
>
> #include <stdio.h>
>
> #ifdef NDEBUG
> #define ASSERT_EQUAL_VARS(a,b) ((void)0)
> #else
> #define ASSERT_FORMAT(x) _Generic(x,int:"%d",default:"?")
> #define ASSERT_PRINT(x) \
> {fprintf(stderr,#x " is ");\
> fprintf(stderr,ASSERT_FORMAT(x),x);\
> fprintf(stderr,"\n");}
> #define ASSERT_FAILURE(a,b) {ASSERT_PRINT(a);ASSERT_PRINT(b);}
> #define ASSERT_EQUAL_VARS(a,b) {if(!(a==b))ASSERT_FAILURE(a,b)}while(0)
> #endif
>
> int main( void )
> { int const a = 2;
> int const b = 3;
> ASSERT_EQUAL_VARS(a,b); }
>
>

That is just one example. Another example from
https://en.cppreference.com/w/c/error/assert:

#include <stdio.h>
// uncomment to disable assert()
// #define NDEBUG
#include <assert.h>
#include <math.h>

int main(void)
{ double x = -1.0;
assert(x >= 0.0);
printf("sqrt(x) = %f\n", sqrt(x));

return 0;
}

output with NDEBUG not defined:
a.out: main.cpp:10: main: Assertion `x >= 0.0' failed.

IMHO worth mentioning is:
x is -1.0

Re: Verbose assert

<example-20220220081810@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20496&group=comp.lang.c#20496

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: 20 Feb 2022 07:18:25 GMT
Organization: Stefan Ram
Lines: 8
Expires: 1 Jul 2022 11:59:58 GMT
Message-ID: <example-20220220081810@ram.dialup.fu-berlin.de>
References: <suq3j4$2r5$1@dont-email.me> <assert-20220219085441@ram.dialup.fu-berlin.de> <suspbj$sip$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de DA3lr4ofZisjbTv6KcXSmAsvRQRLtINDqoSa5NHG7F0D82
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sun, 20 Feb 2022 07:18 UTC

Mehdi Amini <atorrses@gmail.com> writes:
>On 2/19/22 11:26, Stefan Ram wrote:
>> #ifdef NDEBUG
>That is just one example. Another example from

What I wrote was also just one example.

Re: Verbose assert

<8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20497&group=comp.lang.c#20497

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a5d:47cb:0:b0:1e8:593d:d34b with SMTP id o11-20020a5d47cb000000b001e8593dd34bmr11590893wrc.124.1645356226689;
Sun, 20 Feb 2022 03:23:46 -0800 (PST)
X-Received: by 2002:a0c:f84b:0:b0:42c:459a:53a8 with SMTP id
g11-20020a0cf84b000000b0042c459a53a8mr11524934qvo.74.1645356226293; Sun, 20
Feb 2022 03:23:46 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 20 Feb 2022 03:23:46 -0800 (PST)
In-Reply-To: <surf3h$fv0$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
References: <suq3j4$2r5$1@dont-email.me> <bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me>
<j29QJ.14638$LRj9.11090@fx29.iad> <surf3h$fv0$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com>
Subject: Re: Verbose assert
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Sun, 20 Feb 2022 11:23:46 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Öö Tiib - Sun, 20 Feb 2022 11:23 UTC

On Saturday, 19 February 2022 at 21:06:53 UTC+2, Bonita Montero wrote:
> Am 19.02.2022 um 17:38 schrieb Scott Lurndal:
> > Bonita Montero <Bonita....@gmail.com> writes:
> >> Am 19.02.2022 um 17:00 schrieb Scott Lurndal:
> >
> >>>
> >>> void my_assert_msg(const char* filep, int lineno,
> >>> const char* conditionp, const char* fmtp="", ...);
> >>>
> >>> #define MY_ASSERT(condition, ...) \
> >>> do if (unlikely(!(condition))) { \
> >>
> >> Lol, "unlikely", if the performance of debugging-code would be an issue.
> >
> > Indeed, it's quite important from a performance standpoint
> > to help the compiler generate branch-predictor friendly code.
>
> No one cares for the performance of debugging-code. And when
> you compile a perfomant release the debugging-code is stripped.

No one cares about your speed of giving wrong answers.
Assertion failure indicates an arbitrary and unknowable amount of
brokenness in the program state caused by programming errors.
When the assertion is compiled out then that state can be used to
do maximal damage to the runner of program. When the assertion
is not compiled out then the outcome can be used for denial of
service to the runner of program. That is usually milder. Also
assertion failures lot easier to notice, figure out and to fix. So
programmers often choose to define NDEBUG only for translation
units about what profiling indicates that it is worth doing for
performance. And such are often under 5% of code-base.

Re: Verbose assert

<87r17xafpo.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20498&group=comp.lang.c#20498

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Sun, 20 Feb 2022 12:24:19 +0000
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <87r17xafpo.fsf@bsb.me.uk>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <susovh$qvj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="aec5c2d66b7a4745cb34d9baf86fd2a0";
logging-data="32385"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xQ7qhmZGqVGQbKJ+7DTvvcQRTUfh2Yj4="
Cancel-Lock: sha1:FBZAt6yPlwxc4vuK7kF41gyoKDU=
sha1:DOiWnxzAKWJuiFLd0+4c1rziQYE=
X-BSB-Auth: 1.afc25725704c7d7131c7.20220220122419GMT.87r17xafpo.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 20 Feb 2022 12:24 UTC

Mehdi Amini <atorrses@gmail.com> writes:

It seems you want something like this:

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

void my_assert(int cond, const char *fmt, ...)
{
if (!cond) {
va_list al;
va_start(al, fmt);
vfprintf(stderr, fmt, al);
va_end(al);
exit(EXIT_FAILURE);
}
}

#define MY_ASSERT(cond, fmt, ...) \
my_assert(cond, "*** \"%s\" line %d: " fmt, \
__FILE__, __LINE__, __VA_ARGS__)

int main(void)
{
int a = 41, b = 42;
MY_ASSERT(a == b, "%d != %d as required.\n", a, b);
}

Note that this uses string concatenation to build the format, but you
can write a version that will work with non-literal formats.

--
Ben.

Re: Verbose assert

<87ley5acdu.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20499&group=comp.lang.c#20499

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Sun, 20 Feb 2022 13:36:13 +0000
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <87ley5acdu.fsf@bsb.me.uk>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <susovh$qvj$1@dont-email.me>
<87r17xafpo.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="aec5c2d66b7a4745cb34d9baf86fd2a0";
logging-data="1701"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mFSREARYExD0zTXhlD/3RRDKh5zO4TlM="
Cancel-Lock: sha1:MoW6ShJJVgoAlW28k0YsoClhpp4=
sha1:rV3DFEmRbq26zvI4rVkVJ8+YW4o=
X-BSB-Auth: 1.17c72f401ad1a7febb0f.20220220133613GMT.87ley5acdu.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 20 Feb 2022 13:36 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> void my_assert(int cond, const char *fmt, ...)
> {
> if (!cond) {
> va_list al;
> va_start(al, fmt);
> vfprintf(stderr, fmt, al);
> va_end(al);
> exit(EXIT_FAILURE);
> }
> }
>
> #define MY_ASSERT(cond, fmt, ...) \
> my_assert(cond, "*** \"%s\" line %d: " fmt, \
> __FILE__, __LINE__, __VA_ARGS__)

A slight improvement would be to include the condition as a string:

#define MY_ASSERT(cond, fmt, ...) \
my_assert(cond, #cond " in \"%s\" line %d is false. " fmt, \
__FILE__, __LINE__, __VA_ARGS__)
> int main(void)
> {
> int a = 41, b = 42;
> MY_ASSERT(a == b, "%d != %d as required.\n", a, b);

And, frankly, that could be worded better!

> }

--
Ben.

Re: Verbose assert

<sutmua$h92$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20500&group=comp.lang.c#20500

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Sun, 20 Feb 2022 16:32:25 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <sutmua$h92$1@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me>
<j29QJ.14638$LRj9.11090@fx29.iad> <surf3h$fv0$2@dont-email.me>
<8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 20 Feb 2022 15:32:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1932c4bfbc290f5e06e5666be2b733a5";
logging-data="17698"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XT8MDUGCJgk0G362n1bPtY6h6OscEkFI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:3qHfSSbBrlvSTwpjARh+ZCmWqKs=
In-Reply-To: <8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Sun, 20 Feb 2022 15:32 UTC

Am 20.02.2022 um 12:23 schrieb Öö Tiib:
> On Saturday, 19 February 2022 at 21:06:53 UTC+2, Bonita Montero wrote:
>> Am 19.02.2022 um 17:38 schrieb Scott Lurndal:
>>> Bonita Montero <Bonita....@gmail.com> writes:
>>>> Am 19.02.2022 um 17:00 schrieb Scott Lurndal:
>>>
>>>>>
>>>>> void my_assert_msg(const char* filep, int lineno,
>>>>> const char* conditionp, const char* fmtp="", ...);
>>>>>
>>>>> #define MY_ASSERT(condition, ...) \
>>>>> do if (unlikely(!(condition))) { \
>>>>
>>>> Lol, "unlikely", if the performance of debugging-code would be an issue.
>>>
>>> Indeed, it's quite important from a performance standpoint
>>> to help the compiler generate branch-predictor friendly code.
>>
>> No one cares for the performance of debugging-code. And when
>> you compile a perfomant release the debugging-code is stripped.
>
> No one cares about your speed of giving wrong answers.
> Assertion failure indicates an arbitrary and unknowable amount of
> brokenness in the program state caused by programming errors.
> When the assertion is compiled out then that state can be used to
> do maximal damage to the runner of program. When the assertion
> is not compiled out then the outcome can be used for denial of
> service to the runner of program. That is usually milder. Also
> assertion failures lot easier to notice, figure out and to fix.
> So programmers often choose to define NDEBUG only for translation
> units about what profiling indicates that it is worth doing for
> performance. And such are often under 5% of code-base.

The performance of debugging-code doesn't count, so Scott's
unlikely is simply silly.

Re: Verbose assert

<L_tQJ.37807$m1S7.19997@fx36.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20501&group=comp.lang.c#20501

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx36.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Verbose assert
Newsgroups: comp.lang.c
References: <suq3j4$2r5$1@dont-email.me> <bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com> <Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me> <j29QJ.14638$LRj9.11090@fx29.iad> <surf3h$fv0$2@dont-email.me> <8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com> <sutmua$h92$1@dont-email.me>
Lines: 31
Message-ID: <L_tQJ.37807$m1S7.19997@fx36.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sun, 20 Feb 2022 16:28:27 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sun, 20 Feb 2022 16:28:27 GMT
X-Received-Bytes: 2311
 by: Scott Lurndal - Sun, 20 Feb 2022 16:28 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 20.02.2022 um 12:23 schrieb Öö Tiib:

>> No one cares about your speed of giving wrong answers.
>> Assertion failure indicates an arbitrary and unknowable amount of
>> brokenness in the program state caused by programming errors.
>> When the assertion is compiled out then that state can be used to
>> do maximal damage to the runner of program. When the assertion
>> is not compiled out then the outcome can be used for denial of
>> service to the runner of program. That is usually milder. Also
>> assertion failures lot easier to notice, figure out and to fix.
>> So programmers often choose to define NDEBUG only for translation
>> units about what profiling indicates that it is worth doing for
>> performance. And such are often under 5% of code-base.
>
>The performance of debugging-code doesn't count, so Scott's
>unlikely is simply silly.
>

If the invocation of the MY_ASSERT macro is in a performance
sensitive code path, then of course the performance of the
condition test is important.

As Tiib pointed out, assertions aren't removed from production
code in the real world.

Now personally (and professionally), one generally can find
alternate mechanisms to deal with such failures[*] rather than
blindly terminating the application and thus such asserts are rare.

[*] e.g. an API can return an EINVAL error.

Re: Verbose assert

<G4uQJ.37808$m1S7.16870@fx36.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20502&group=comp.lang.c#20502

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx36.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Verbose assert
Newsgroups: comp.lang.c
References: <suq3j4$2r5$1@dont-email.me> <bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com> <Gu8QJ.14770$XFM9.1016@fx18.iad> <susovh$qvj$1@dont-email.me>
Lines: 114
Message-ID: <G4uQJ.37808$m1S7.16870@fx36.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sun, 20 Feb 2022 16:34:46 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sun, 20 Feb 2022 16:34:46 GMT
X-Received-Bytes: 4273
X-Original-Bytes: 4222
 by: Scott Lurndal - Sun, 20 Feb 2022 16:34 UTC

Mehdi Amini <atorrses@gmail.com> writes:
>On 2/19/22 19:30, Scott Lurndal wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>> On Saturday, 19 February 2022 at 06:44:18 UTC, Mehdi Amini Valashani son of Bahram wrote:
>>>> Hi,
>>>>
>>>> Considering usage of "assert" , I want a more informative output from
>>>> it. Consider:
>>>>
>>>> // Code:
>>>> #include <assert.h>
>>>> #include <stdio.h>
>>>> #include <stdlib.h>
>>>>
>>>> int main(void)
>>>> {
>>>> int b=3;
>>>> int a=2;
>>>>
>>>> assert(a==b);
>>>>
>>>> return 0;
>>>> }
>>>>
>>>> Output of gcc:
>>>> verbose_assert.out: verbose_assert.c:10: main: Assertion `a==b' failed.
>>>> Aborted (core dumped)
>>>>
>>>> Output of clang:
>>>> verbose_assert.out: verbose_assert.c:10: int main(void): Assertion
>>>> `a==b' failed.
>>>> Aborted (core dumped)
>>>>
>>>> I want more details in compiler's output , like for example:
>>>> a is 2
>>>> b is 3
>>>>
>>> The onyl way to do this would be to patch the compiler itself. You can
>>> easily write your own assert() macro, but the expression a == b just resolves
>>> to either 1 or 0 within the macro. You can stringify it, but you can't link
>>> the string component "a" to the variable a.
>>
>> void my_assert_msg(const char* filep, int lineno,
>> const char* conditionp, const char* fmtp="", ...);
>>
>> #define MY_ASSERT(condition, ...) \
>> do if (unlikely(!(condition))) { \
>> my_assert_msg(__FILE__,__LINE__, #condition, ## __VA_ARGS__); \
>> abort(); \
>> } while(0)
>>
>> #ifndef ASSERT
>> # define ASSERT MY_ASSERT
>> #endif
>
>Complete code :
>#include <stdio.h>
>#include <stdlib.h>
>
>void my_assert_msg(const char* filep, int lineno,
> const char* conditionp, const char* fmtp="", ...);
>
>#define MY_ASSERT(condition, ...) \
> do if (unlikely(!(condition))) { \
> my_assert_msg(__FILE__,__LINE__, #condition, ## __VA_ARGS__); \
> abort(); \
> } while(0)
>
>#ifndef ASSERT
># define ASSERT MY_ASSERT
>#endif
>
>int main(void)
>{
> int a,b;
> a=2;
> b=3;
>
> MY_ASSERT(a==b);
>
> return 0;
>}
>
>I get this :
>
>$ clang -Wall -Wextra -pedantic -std=c11 custom_assert2.c -o
>custom_assert2.out
>custom_assert2.c:6:61: error: C does not support default arguments
> const char* conditionp, const char* fmtp="", ...);
> ^~~
>custom_assert2.c:10:53: warning: token pasting of ',' and __VA_ARGS__ is
>a GNU extension [-Wgnu-zero-variadic-macro-arguments]
> my_assert_msg(__FILE__,__LINE__, #condition, ## __VA_ARGS__); \
> ^
>custom_assert2.c:24:5: warning: implicit declaration of function
>'unlikely' is invalid in C99 [-Wimplicit-function-declaration]
> MY_ASSERT(a==b);
> ^
>custom_assert2.c:9:11: note: expanded from macro 'MY_ASSERT'
> do if (unlikely(!(condition))) { \
> ^
>2 warnings and 1 error generated.

Apologies.

#define unlikely(x) __builtin_expect(!!(x), 0)

You'll also need to actually implement my_assert_msg. It will
be a good exercise for you.

And it will probably require changes for C (the code posted was for C++
which supports default arguments - go ahead and remove the '=""' from
the function prototype). Hint - use vsnprintf in my_assert_msg.

Re: Verbose assert

<20220220091816.883@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20503&group=comp.lang.c#20503

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Sun, 20 Feb 2022 17:30:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <20220220091816.883@kylheku.com>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me>
<j29QJ.14638$LRj9.11090@fx29.iad> <surf3h$fv0$2@dont-email.me>
<8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com>
<sutmua$h92$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 20 Feb 2022 17:30:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="05e270eb53b3f247700a85436199fb36";
logging-data="29404"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qWMvhmdwTu85EwCuHhiki0ZlmxlPJfeY="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Z7DzWrjVYaDfH4Yu4OsE9YbTwqY=
 by: Kaz Kylheku - Sun, 20 Feb 2022 17:30 UTC

On 2022-02-20, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 20.02.2022 um 12:23 schrieb Öö Tiib:
>> On Saturday, 19 February 2022 at 21:06:53 UTC+2, Bonita Montero wrote:
>>> Am 19.02.2022 um 17:38 schrieb Scott Lurndal:
>>>> Bonita Montero <Bonita....@gmail.com> writes:
>>>>> Am 19.02.2022 um 17:00 schrieb Scott Lurndal:
>>>>
>>>>>>
>>>>>> void my_assert_msg(const char* filep, int lineno,
>>>>>> const char* conditionp, const char* fmtp="", ...);
>>>>>>
>>>>>> #define MY_ASSERT(condition, ...) \
>>>>>> do if (unlikely(!(condition))) { \
>>>>>
>>>>> Lol, "unlikely", if the performance of debugging-code would be an issue.
>>>>
>>>> Indeed, it's quite important from a performance standpoint
>>>> to help the compiler generate branch-predictor friendly code.
>>>
>>> No one cares for the performance of debugging-code. And when
>>> you compile a perfomant release the debugging-code is stripped.
>>
>> No one cares about your speed of giving wrong answers.
>> Assertion failure indicates an arbitrary and unknowable amount of
>> brokenness in the program state caused by programming errors.
>> When the assertion is compiled out then that state can be used to
>> do maximal damage to the runner of program. When the assertion
>> is not compiled out then the outcome can be used for denial of
>> service to the runner of program. That is usually milder. Also
>> assertion failures lot easier to notice, figure out and to fix.
>> So programmers often choose to define NDEBUG only for translation
>> units about what profiling indicates that it is worth doing for
>> performance. And such are often under 5% of code-base.
>
> The performance of debugging-code doesn't count, so Scott's
> unlikely is simply silly.

In some software projects, there is a practice of leaving assertions
in production code. There may not even be a provided mechanism to
compile them out. ISO C calls the disabling macro NDEBUG, suggesting
"no debugging", but that doesn't mean that even that ISO C macro
necessarily debugging *instrumentation* that is to be removed from the
product, the way oscilloscope or multimeter probes are removed from a
circuit board. "Debugging" can refer to debug *support*. For instance,
like having test points on a circuit board for easier verification,
which are retained in the production board. Assertions don't just
provide debug support, but a predictable, safe(r) mode of failure for
problems that could go entirely undetected (which also makes the
situation easier to debug, as a side effect).

In the software that I'm currently working on at work, the regression
test suite includes test cases that check that certain violations of
contracts produce the assertions.

For each function, those conditions that are required in such a way
that an assertion will be issued if they are not satisfied are
documented as such.

C. A. R Hoare, wrote

"What would we think of a sailing enthusiast who wears his lifejacket
when training on dry land, but takes it off as soon as he goes to sea?",

evidently in "Hints on programming language design", Stanford Artificial
Intelligence Laboratory memo AIM-24, Stanford University technical
report no. STAN-CS-73-403, 1973.

And so, if you have assertion checks in production code, their overhead
may matter in some cases. If some frequently called function contains an
assert check, a hint to the compiler that the failing branch is not
expected to be taken could save some valuable cycles.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Verbose assert

<48aabd7d-c853-42eb-8dc2-1deb23ec5834n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20504&group=comp.lang.c#20504

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a7b:cb44:0:b0:37c:4e2d:3bb2 with SMTP id v4-20020a7bcb44000000b0037c4e2d3bb2mr18559462wmj.96.1645386482003;
Sun, 20 Feb 2022 11:48:02 -0800 (PST)
X-Received: by 2002:a37:bb02:0:b0:47c:9965:3b6b with SMTP id
l2-20020a37bb02000000b0047c99653b6bmr10385617qkf.190.1645386481534; Sun, 20
Feb 2022 11:48:01 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 20 Feb 2022 11:48:01 -0800 (PST)
In-Reply-To: <L_tQJ.37807$m1S7.19997@fx36.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:157e:13ad:a74e:6815;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:157e:13ad:a74e:6815
References: <suq3j4$2r5$1@dont-email.me> <bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me>
<j29QJ.14638$LRj9.11090@fx29.iad> <surf3h$fv0$2@dont-email.me>
<8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com> <sutmua$h92$1@dont-email.me>
<L_tQJ.37807$m1S7.19997@fx36.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <48aabd7d-c853-42eb-8dc2-1deb23ec5834n@googlegroups.com>
Subject: Re: Verbose assert
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Sun, 20 Feb 2022 19:48:01 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Sun, 20 Feb 2022 19:48 UTC

On Sunday, 20 February 2022 at 16:28:52 UTC, Scott Lurndal wrote:
>
> As Tiib pointed out, assertions aren't removed from production
> code in the real world.
>
When I was a games programmer, we had a console with a CD. We
were allowed two error messages. "Drive door open" and "disk dirty".

Re: Verbose assert

<xRBQJ.2921$3Pje.665@fx09.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20505&group=comp.lang.c#20505

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Verbose assert
Newsgroups: comp.lang.c
References: <suq3j4$2r5$1@dont-email.me> <bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com> <Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me> <j29QJ.14638$LRj9.11090@fx29.iad> <surf3h$fv0$2@dont-email.me> <8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com> <sutmua$h92$1@dont-email.me> <20220220091816.883@kylheku.com>
Lines: 13
Message-ID: <xRBQJ.2921$3Pje.665@fx09.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 21 Feb 2022 01:24:45 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 21 Feb 2022 01:24:45 GMT
X-Received-Bytes: 1526
 by: Scott Lurndal - Mon, 21 Feb 2022 01:24 UTC

Kaz Kylheku <480-992-1380@kylheku.com> writes:
>On 2022-02-20, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 20.02.2022 um 12:23 schrieb Öö Tiib:

>
>And so, if you have assertion checks in production code, their overhead
>may matter in some cases. If some frequently called function contains an
>assert check, a hint to the compiler that the failing branch is not
>expected to be taken could save some valuable cycles.

And, of even more benefit, move the "then" clause in the codestream
to a different cache line, thus improving the icache hit rate by
some small amount.

Re: Verbose assert

<suva4b$tgs$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20506&group=comp.lang.c#20506

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Mon, 21 Feb 2022 07:06:03 +0100
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <suva4b$tgs$1@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me>
<j29QJ.14638$LRj9.11090@fx29.iad> <surf3h$fv0$2@dont-email.me>
<8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com>
<sutmua$h92$1@dont-email.me> <L_tQJ.37807$m1S7.19997@fx36.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 21 Feb 2022 06:06:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d9f24c84a27f4a9fb744111a63030da0";
logging-data="30236"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EfQfPr69KblLlcyFSLA7xSNpyA/xR42g="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:iT/TFZuNuRIKFPGIsZApdRhg3YE=
In-Reply-To: <L_tQJ.37807$m1S7.19997@fx36.iad>
Content-Language: de-DE
 by: Bonita Montero - Mon, 21 Feb 2022 06:06 UTC

Am 20.02.2022 um 17:28 schrieb Scott Lurndal:

> If the invocation of the MY_ASSERT macro is in a performance
> sensitive code path, then of course the performance of the
> condition test is important.

Debugging-code hasn't any optimizations anyway
and therefore is never performance-sensitive.

Re: Verbose assert

<suva5n$tgs$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20507&group=comp.lang.c#20507

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Mon, 21 Feb 2022 07:06:47 +0100
Organization: A noiseless patient Spider
Lines: 4
Message-ID: <suva5n$tgs$2@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <sur59v$1tv$1@dont-email.me>
<j29QJ.14638$LRj9.11090@fx29.iad> <surf3h$fv0$2@dont-email.me>
<8c40d7d6-9cda-44c5-b1b6-0dbeed3a1f3cn@googlegroups.com>
<sutmua$h92$1@dont-email.me> <20220220091816.883@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 21 Feb 2022 06:06:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d9f24c84a27f4a9fb744111a63030da0";
logging-data="30236"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IGSOXtcvs3HVgAPSxs/IJDxbXiLMnGPo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:93sjeYyKK8PCVdqqnw5rzmmFjFc=
In-Reply-To: <20220220091816.883@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Mon, 21 Feb 2022 06:06 UTC

> In some software projects, there is a practice of leaving assertions
> in production code.

To have an INT3 so that the application crashes at the customer ?

Re: Verbose assert

<suvcli$9iu$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20508&group=comp.lang.c#20508

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: atorr...@gmail.com (Mehdi Amini)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Mon, 21 Feb 2022 10:19:21 +0330
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <suvcli$9iu$1@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<assert-20220219085441@ram.dialup.fu-berlin.de> <suspbj$sip$1@dont-email.me>
<example-20220220081810@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 21 Feb 2022 06:49:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="59b17b46b537588a674f2c6a8a7328c9";
logging-data="9822"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4RpFERx/GSX0LmD8XWGniXw2nr13+mgY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:YZ1pzpHdpL3VkwKt2l5M+ELqU8w=
In-Reply-To: <example-20220220081810@ram.dialup.fu-berlin.de>
Content-Language: en-US
 by: Mehdi Amini - Mon, 21 Feb 2022 06:49 UTC

On 2/20/22 10:48, Stefan Ram wrote:
> Mehdi Amini <atorrses@gmail.com> writes:
>> On 2/19/22 11:26, Stefan Ram wrote:
>>> #ifdef NDEBUG
>> That is just one example. Another example from
>
> What I wrote was also just one example.
>
>

Sorry I did not explain my question properly. When using "assert" I want
to read the values of it's variables in case of "assert"'s failure.

Re: Verbose assert

<suve9h$hcs$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20509&group=comp.lang.c#20509

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: atorr...@gmail.com (Mehdi Amini)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Mon, 21 Feb 2022 10:47:03 +0330
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <suve9h$hcs$1@dont-email.me>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <susovh$qvj$1@dont-email.me>
<87r17xafpo.fsf@bsb.me.uk> <87ley5acdu.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 21 Feb 2022 07:17:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="59b17b46b537588a674f2c6a8a7328c9";
logging-data="17820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/G/xuG6Ca1RnS0AyMW5ttNjbvHGePTIEY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:3/tThPSu4gdUTafJnCB2wXEs4wg=
In-Reply-To: <87ley5acdu.fsf@bsb.me.uk>
Content-Language: en-US
 by: Mehdi Amini - Mon, 21 Feb 2022 07:17 UTC

On 2/20/22 17:06, Ben Bacarisse wrote:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>

[...]

>
> A slight improvement would be to include the condition as a string:
>
> #define MY_ASSERT(cond, fmt, ...) \
> my_assert(cond, #cond " in \"%s\" line %d is false. " fmt, \
> __FILE__, __LINE__, __VA_ARGS__)
>> int main(void)
>> {
>> int a = 41, b = 42;
>> MY_ASSERT(a == b, "%d != %d as required.\n", a, b);
>
> And, frankly, that could be worded better!
>
>> }
>

I wanted to add __FUNCTION__ to above code too. Unfortunately this is
not part of c11 standard.

$ gcc -Wall -Wextra -pedantic -std=c11 verbose_assert2.c -o
verbose_assert2.out
verbose_assert2.c: In function ‘main’:
verbose_assert2.c:29:28: warning: ISO C does not support ‘__FUNCTION__’
predefined identifier [-Wpedantic]
29 | __FILE__, __FUNCTION__ , __LINE__, __VA_ARGS__)
| ^~~~~~~~~~~~
verbose_assert2.c:35:8: note: in expansion of macro ‘MY_ASSERT’
35 | MY_ASSERT(a == b, "%d != %d as required.\n", a, b);
| ^~~~~~~~~

Re: Verbose assert

<87zgmkobo7.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20510&group=comp.lang.c#20510

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Verbose assert
Date: Mon, 21 Feb 2022 00:40:08 -0800
Organization: None to speak of
Lines: 18
Message-ID: <87zgmkobo7.fsf@nosuchdomain.example.com>
References: <suq3j4$2r5$1@dont-email.me>
<bee669c3-c65b-4476-9989-0e1c063c8504n@googlegroups.com>
<Gu8QJ.14770$XFM9.1016@fx18.iad> <susovh$qvj$1@dont-email.me>
<87r17xafpo.fsf@bsb.me.uk> <87ley5acdu.fsf@bsb.me.uk>
<suve9h$hcs$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="89d3082827997fea00af9c93ec78ba89";
logging-data="10483"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lQwAdfHZIHpLhP/gynvBB"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:3VgGp1dv436dARMt/5dddtR2Mpw=
sha1:5YA5lKDoNDLTo3NFJIUpieE8cJQ=
 by: Keith Thompson - Mon, 21 Feb 2022 08:40 UTC

Mehdi Amini <atorrses@gmail.com> writes:
[...]
> I wanted to add __FUNCTION__ to above code too. Unfortunately this is
> not part of c11 standard.

It's spelled __func__ .

__FUNCTION__ is non-standard. gcc's documentation says:

'__FUNCTION__' is another name for '__func__', provided for backward
compatibility with old versions of GCC.

Microsoft's implementation defines __FUNCTION__ as a predefined macro.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor