Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Writing software is more fun than working.


devel / comp.lang.c / sprintf_s() syntax?

SubjectAuthor
* sprintf_s() syntax?Sams Lara
+- Re: sprintf_s() syntax?Joe Pfeiffer
+* Re: sprintf_s() syntax?James Kuyper
|`- Re: sprintf_s() syntax?Joe Pfeiffer
+- Re: sprintf_s() syntax?Manfred
+* Re: sprintf_s() syntax?Ben Bacarisse
|`- Re: sprintf_s() syntax?Öö Tiib
+* Re: sprintf_s() syntax?Andrey Tarasevich
|`* Re: sprintf_s() syntax?Andrey Tarasevich
| `* Re: sprintf_s() syntax?James Kuyper
|  +- Re: sprintf_s() syntax?Manfred
|  `* Re: sprintf_s() syntax?Andrey Tarasevich
|   `* Re: sprintf_s() syntax?James Kuyper
|    `- Re: sprintf_s() syntax?Andrey Tarasevich
`- Re: sprintf_s() syntax?Sams Lara

1
sprintf_s() syntax?

<t28beo$u36$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!nOqLI1EbCan+82M4Y2qJhQ.user.46.165.242.91.POSTED!not-for-mail
From: samlara...@gmail.com (Sams Lara)
Newsgroups: comp.lang.c
Subject: sprintf_s() syntax?
Date: Sat, 2 Apr 2022 03:00:00 +0100
Organization: Aioe.org NNTP Server
Message-ID: <t28beo$u36$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="30822"; posting-host="nOqLI1EbCan+82M4Y2qJhQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Sams Lara - Sat, 2 Apr 2022 02:00 UTC

Does anybody know how to make use of sprintf_s() for this small function?

void sendOutput(double* arr, int yrs) {
��� char outstring[100];
��� int i;

��� printf("\nRESULTS: \n\n");

��� for (i = 0; i < yrs; i++)
��� {
��� ��� sprintf(outstring, "Year %3d:� %10.2f\n", i, arr[i]);
��� ��� // printf("Year %3d:� %10.2f\n", i, arr[i]);
��� ��� printf("%s", outstring);
��� }
��� printf("\n");
}

When I am using sprintf() as shown above, it works but when I try to
make use of sprintf_s() (for latest versions of compilers) it prints
nothing so where am I going wrong? I know it is the syntax problem and I
am stuck with this. The code I have tried is:

sprintf_s(outstring, "Year %3d:� %10.2f\n", i, arr[i]);

The outstring is an array of 100 characters as shown in the function but
how do I make use of it in the code (if at all it is necessary).� the
example given here is a bit confusing:

<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l?view=msvc-170>

As I understand it, sprintf() is deprecated so modern compilers gives
error message. I am using VS 2022 from Microsoft.

Re: sprintf_s() syntax?

<1b4k3c18hl.fsf@pfeifferfamily.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: pfeif...@cs.nmsu.edu (Joe Pfeiffer)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Fri, 01 Apr 2022 21:15:18 -0600
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <1b4k3c18hl.fsf@pfeifferfamily.net>
References: <t28beo$u36$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="651c317ef735b3f1bd0b9da4a0c94fe9";
logging-data="20313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/b+CG77LLU7iF8nDzyEneNFMScwEci3wg="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:8b75cOfDg16m3v8pug/VGUvyerU=
sha1:1GituXF/+aQ6goHa9+dhG5xYkXs=
 by: Joe Pfeiffer - Sat, 2 Apr 2022 03:15 UTC

Sams Lara <samlara622@gmail.com> writes:

> Does anybody know how to make use of sprintf_s() for this small function?
>
> void sendOutput(double* arr, int yrs) {
>     char outstring[100];
>     int i;
>
>     printf("\nRESULTS: \n\n");
>
>     for (i = 0; i < yrs; i++)
>     {
>         sprintf(outstring, "Year %3d:  %10.2f\n", i, arr[i]);
>         // printf("Year %3d:  %10.2f\n", i, arr[i]);
>         printf("%s", outstring);
>     }
>     printf("\n");
> }
>
> When I am using sprintf() as shown above, it works but when I try to
> make use of sprintf_s() (for latest versions of compilers) it prints
> nothing so where am I going wrong? I know it is the syntax problem and I
> am stuck with this. The code I have tried is:
>
> sprintf_s(outstring, "Year %3d:  %10.2f\n", i, arr[i]);
>
> The outstring is an array of 100 characters as shown in the function but
> how do I make use of it in the code (if at all it is necessary).  the
> example given here is a bit confusing:
>
> <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l?view=msvc-170>
>
> As I understand it, sprintf() is deprecated so modern compilers gives
> error message. I am using VS 2022 from Microsoft.

You aren't passing it the second parameter. You should be calling it as

sprintf_s(outstring, 100, "Year %3d:  %10.2f\n", i, arr[i]);

or, better

sprintf_s(outstring, sizeof(outstring), "Year %3d:  %10.2f\n", i, arr[i]);

Re: sprintf_s() syntax?

<t28l1e$v61$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Sat, 2 Apr 2022 00:56:14 -0400
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <t28l1e$v61$1@dont-email.me>
References: <t28beo$u36$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 2 Apr 2022 04:56:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffae8f7b3ad345bac949b42f088a7513";
logging-data="31937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HQcEmEPsa89Ikfvg6lCVjWmar/Ow/ABg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:Y9klqD/M4ZKVdidBgOdYW68m7JQ=
In-Reply-To: <t28beo$u36$1@gioia.aioe.org>
Content-Language: en-US
 by: James Kuyper - Sat, 2 Apr 2022 04:56 UTC

On 4/1/22 22:00, Sams Lara wrote:
> Does anybody know how to make use of sprintf_s() for this small function?
>
> void sendOutput(double* arr, int yrs) {
>     char outstring[100];
>     int i;
>
>     printf("\nRESULTS: \n\n");
>
>     for (i = 0; i < yrs; i++)
>     {
>         sprintf(outstring, "Year %3d:  %10.2f\n", i, arr[i]);...
> sprintf_s(outstring, "Year %3d:  %10.2f\n", i, arr[i]);

The thing that makes sprintf_s() different from sprintf() (and
supposedly safer to use) is that sprintf() takes one additional argument
of type rsize_t (which is the same type as size_t) after the format
string, which is the maximum number of characters that should be printed
by sprintf_s() to the output string. You should be passing `sizeof
outstring` for that argument.

Instead, you're passing it 'i' as its third argument, which is likely to
be the wrong size. Even if it were the right size, sprintf_s() would
then try to interpret arr[i] as an int to match "%3d". Even if that
worked, it would then go on to try to find a match for "%10.2f", and you
haven't provided one.

....
> As I understand it, sprintf() is deprecated so modern compilers gives
> error message. I am using VS 2022 from Microsoft.

Microsoft deprecates sprintf(), the C standard does not.

Re: sprintf_s() syntax?

<1bwng7zi68.fsf@pfeifferfamily.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: pfeif...@cs.nmsu.edu (Joe Pfeiffer)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Sat, 02 Apr 2022 08:14:23 -0600
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <1bwng7zi68.fsf@pfeifferfamily.net>
References: <t28beo$u36$1@gioia.aioe.org> <t28l1e$v61$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="651c317ef735b3f1bd0b9da4a0c94fe9";
logging-data="4988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tmE2Nw+lLJWe6EZrcMwQ78S5fcGeVOfs="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:pjuc4tTKAlfBGcVg49e38Ue2Hc4=
sha1:xCJHBYABjZMawSbvp4LXSEzJBbQ=
 by: Joe Pfeiffer - Sat, 2 Apr 2022 14:14 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:

> On 4/1/22 22:00, Sams Lara wrote:
>> Does anybody know how to make use of sprintf_s() for this small function?
>>
>> void sendOutput(double* arr, int yrs) {
>>     char outstring[100];
>>     int i;
>>
>>     printf("\nRESULTS: \n\n");
>>
>>     for (i = 0; i < yrs; i++)
>>     {
>>         sprintf(outstring, "Year %3d:  %10.2f\n", i, arr[i]);...
>> sprintf_s(outstring, "Year %3d:  %10.2f\n", i, arr[i]);
>
> The thing that makes sprintf_s() different from sprintf() (and
> supposedly safer to use) is that sprintf() takes one additional argument
> of type rsize_t (which is the same type as size_t) after the format
> string, which is the maximum number of characters that should be printed
> by sprintf_s() to the output string. You should be passing `sizeof
> outstring` for that argument.

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l?view=msvc-170
says the size of the output buffer is the second argument, going before
the format string.

> Instead, you're passing it 'i' as its third argument, which is likely to
> be the wrong size. Even if it were the right size, sprintf_s() would
> then try to interpret arr[i] as an int to match "%3d". Even if that
> worked, it would then go on to try to find a match for "%10.2f", and you
> haven't provided one.
>
> ...
>> As I understand it, sprintf() is deprecated so modern compilers gives
>> error message. I am using VS 2022 from Microsoft.
>
> Microsoft deprecates sprintf(), the C standard does not.

Re: sprintf_s() syntax?

<t2a1hk$bj5$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Sat, 2 Apr 2022 19:35:46 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t2a1hk$bj5$1@gioia.aioe.org>
References: <t28beo$u36$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="11877"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Sat, 2 Apr 2022 17:35 UTC

On 4/2/2022 4:00 AM, Sams Lara wrote:
> Does anybody know how to make use of sprintf_s() for this small function?
>
> void sendOutput(double* arr, int yrs) {
>     char outstring[100];
>     int i;
>
>     printf("\nRESULTS: \n\n");
>
>     for (i = 0; i < yrs; i++)
>     {
>         sprintf(outstring, "Year %3d:  %10.2f\n", i, arr[i]);
>         // printf("Year %3d:  %10.2f\n", i, arr[i]);
>         printf("%s", outstring);
>     }
>     printf("\n");
> }
>
> When I am using sprintf() as shown above, it works but when I try to
> make use of sprintf_s() (for latest versions of compilers) it prints
> nothing so where am I going wrong? I know it is the syntax problem and I
> am stuck with this. The code I have tried is:
>
> sprintf_s(outstring, "Year %3d:  %10.2f\n", i, arr[i]);

If it is a syntax problem the compiler should have given an error
message that would tell what is wrong.

>
> The outstring is an array of 100 characters as shown in the function but
> how do I make use of it in the code (if at all it is necessary).  the
> example given here is a bit confusing:
>
> <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l?view=msvc-170>

As others have pointed out, you need to pass in the length of the buffer
as the second argument:

sprintf_s(outstring, 100, "Year %3d: %10.2f\n", i, arr[i]);

You should have got an error message if you compiled the call as you
showed above in C mode.

MS also provides a templated C++ version that is able to infer the array
size when passed in a C-style array buffer, wherein you don't need to
explicitly pass in the size of the buffer. This version would be used
only if compiled in C++ mode.

>
> As I understand it, sprintf() is deprecated so modern compilers gives
> error message. I am using VS 2022 from Microsoft.
>

You shouldn't get an error message for using sprintf. You probably get
some warning.

sprintf and friends are deprecated by recent Microsoft compilers. They
are not deprecated by other compilers, for example glibc with gcc.
In fact the family of "_s" functions belong to Annex K of the C
standard, which is optional for implementations, and somewhat
controversial, in the sense that some vendors (e.g. the GNU people) do
not consider it a good solution for the problem it is supposed to solve.

Re: sprintf_s() syntax?

<8735ivgt9p.fsf@bsb.me.uk>

  copy mid

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

  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: sprintf_s() syntax?
Date: Sat, 02 Apr 2022 20:49:38 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <8735ivgt9p.fsf@bsb.me.uk>
References: <t28beo$u36$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="2e1f6aa93b0d51b1bbafc7b427b9200a";
logging-data="27661"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182uVWhKbu3FWdxcwuPNGIak+07WoOHjtE="
Cancel-Lock: sha1:4Ny7ZLWM7axQggRXnCveyozZO1U=
sha1:KF72Din1yRdkxFEXsN15NMGhrG8=
X-BSB-Auth: 1.d1129a708a887f1dd527.20220402204938BST.8735ivgt9p.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 2 Apr 2022 19:49 UTC

Sams Lara <samlara622@gmail.com> writes:

> void sendOutput(double* arr, int yrs) {
>     char outstring[100];
>     int i;
>
>     printf("\nRESULTS: \n\n");
>
>     for (i = 0; i < yrs; i++)
>     {
>         sprintf(outstring, "Year %3d:  %10.2f\n", i, arr[i]);
>         // printf("Year %3d:  %10.2f\n", i, arr[i]);
>         printf("%s", outstring);
>     }
>     printf("\n");
> }
>
> When I am using sprintf() as shown above, it works but when I try to
> make use of sprintf_s() (for latest versions of compilers) it prints
> nothing so where am I going wrong? I know it is the syntax problem and I
> am stuck with this. The code I have tried is:
>
> sprintf_s(outstring, "Year %3d:  %10.2f\n", i, arr[i]);

I think you have all the answers you need about sprintf_s, but no one
seems to have mentioned the standard function snprintf. It is similar
to sprintf_s, though the latter does more run-time checks. sprintf_s is
also sort of standard C, but it's part of Annex K which is optional.

--
Ben.

Re: sprintf_s() syntax?

<077349a2-bfd2-42d2-93f7-88090de78d01n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:3184:b0:67d:cce9:bab4 with SMTP id bi4-20020a05620a318400b0067dcce9bab4mr11178751qkb.685.1648984021187;
Sun, 03 Apr 2022 04:07:01 -0700 (PDT)
X-Received: by 2002:a05:622a:5da0:b0:2eb:b157:5b6 with SMTP id
fu32-20020a05622a5da000b002ebb15705b6mr1941556qtb.404.1648984021046; Sun, 03
Apr 2022 04:07:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 3 Apr 2022 04:07:00 -0700 (PDT)
In-Reply-To: <8735ivgt9p.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=145.14.29.114; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 145.14.29.114
References: <t28beo$u36$1@gioia.aioe.org> <8735ivgt9p.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <077349a2-bfd2-42d2-93f7-88090de78d01n@googlegroups.com>
Subject: Re: sprintf_s() syntax?
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Sun, 03 Apr 2022 11:07:01 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 33
 by: Öö Tiib - Sun, 3 Apr 2022 11:07 UTC

On Saturday, 2 April 2022 at 22:49:51 UTC+3, Ben Bacarisse wrote:
> Sams Lara <samla...@gmail.com> writes:
>
> > void sendOutput(double* arr, int yrs) {
> > char outstring[100];
> > int i;
> >
> > printf("\nRESULTS: \n\n");
> >
> > for (i = 0; i < yrs; i++)
> > {
> > sprintf(outstring, "Year %3d: %10.2f\n", i, arr[i]);
> > // printf("Year %3d: %10.2f\n", i, arr[i]);
> > printf("%s", outstring);
> > }
> > printf("\n");
> > }
> >
> > When I am using sprintf() as shown above, it works but when I try to
> > make use of sprintf_s() (for latest versions of compilers) it prints
> > nothing so where am I going wrong? I know it is the syntax problem and I
> > am stuck with this. The code I have tried is:
> >
> > sprintf_s(outstring, "Year %3d: %10.2f\n", i, arr[i]);
> I think you have all the answers you need about sprintf_s, but no one
> seems to have mentioned the standard function snprintf. It is similar
> to sprintf_s, though the latter does more run-time checks. sprintf_s is
> also sort of standard C, but it's part of Annex K which is optional.

Usage of snprintf is good advice as Annex K is optional. Even
MS itself implemented it with differences.
Also it is unsure if that constraint_handler makes it simpler or
more confused to find programming errors.

Re: sprintf_s() syntax?

<t2drrb$iq4$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Sun, 3 Apr 2022 21:23:05 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <t2drrb$iq4$1@dont-email.me>
References: <t28beo$u36$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Apr 2022 04:23:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="498b302a2a083ec42509e3966902c506";
logging-data="19268"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IQjCtHd0YNqBhfpXfbr6c"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:Lxp2h8aQbgShn8w9RkM5pHtvu5s=
In-Reply-To: <t28beo$u36$1@gioia.aioe.org>
Content-Language: en-US
 by: Andrey Tarasevich - Mon, 4 Apr 2022 04:23 UTC

On 4/1/2022 7:00 PM, Sams Lara wrote:
> make use of sprintf_s() (for latest versions of compilers) it prints
> nothing so where am I going wrong? I know it is the syntax problem and I
> am stuck with this. The code I have tried is:

Firstly, I don't see `sprintf_s` in your code. Why are you asking a
question about `sprintf_s` and suppling code that doesn't have
`sprintf_s` in it?

Secondly, if you simply replaced `sprintf` with `sprintf_s` your code
became invalid. Your compiler clearly told you where the problem is by
issuing a diagnostic message. Why did you decide to ignore that
diagnostic message and ask an abstract question here instead? (And here
you don't even mention the diagnostic message.)

--
Best regards,
Andrey Tarasevich

Re: sprintf_s() syntax?

<t2druh$iq4$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Sun, 3 Apr 2022 21:24:48 -0700
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <t2druh$iq4$2@dont-email.me>
References: <t28beo$u36$1@gioia.aioe.org> <t2drrb$iq4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Apr 2022 04:24:49 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="498b302a2a083ec42509e3966902c506";
logging-data="19268"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xbiS09Uay5OhsDmrNQmod"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:qmYyY0ShZ+F7Yllj8OpApz7JYsI=
In-Reply-To: <t2drrb$iq4$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Mon, 4 Apr 2022 04:24 UTC

On 4/3/2022 9:23 PM, Andrey Tarasevich wrote:
> On 4/1/2022 7:00 PM, Sams Lara wrote:
>> make use of sprintf_s() (for latest versions of compilers) it prints
>> nothing so where am I going wrong? I know it is the syntax problem and I
>> am stuck with this. The code I have tried is:
>
> Firstly, I don't see `sprintf_s` in your code. Why are you asking a
> question about `sprintf_s` and suppling code that doesn't have
> `sprintf_s` in it?
>
> Secondly, if you simply replaced `sprintf` with `sprintf_s` your code
> became invalid. Your compiler clearly told you where the problem is by
> issuing a diagnostic message. Why did you decide to ignore that
> diagnostic message and ask an abstract question here instead? (And here
> you don't even mention the diagnostic message.)
>

OK, I missed this part

> The code I have tried is:
> sprintf_s(outstring, "Year %3d: %10.2f\n", i, arr[i]);

But my "secondly" still stands.

--
Best regards,
Andrey Tarasevich

Re: sprintf_s() syntax?

<t2f2bs$ac2$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Mon, 4 Apr 2022 11:20:28 -0400
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <t2f2bs$ac2$1@dont-email.me>
References: <t28beo$u36$1@gioia.aioe.org> <t2drrb$iq4$1@dont-email.me>
<t2druh$iq4$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Apr 2022 15:20:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="01fb0ae176104dc9775187b1cd047d4b";
logging-data="10626"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ceXyxUNPt2TFxYl1mzEsIlSMrbuU3HH8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:ugq1nMG+SHJMVl/d7oOL+WeOZFI=
In-Reply-To: <t2druh$iq4$2@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Mon, 4 Apr 2022 15:20 UTC

On 4/4/22 00:24, Andrey Tarasevich wrote:
> On 4/3/2022 9:23 PM, Andrey Tarasevich wrote:
>> On 4/1/2022 7:00 PM, Sams Lara wrote:
>>> make use of sprintf_s() (for latest versions of compilers) it prints
>>> nothing so where am I going wrong? I know it is the syntax problem and I
>>> am stuck with this. The code I have tried is:
>>
>> Firstly, I don't see `sprintf_s` in your code. Why are you asking a
>> question about `sprintf_s` and suppling code that doesn't have
>> `sprintf_s` in it?
>>
>> Secondly, if you simply replaced `sprintf` with `sprintf_s` your code
>> became invalid. Your compiler clearly told you where the problem is by
>> issuing a diagnostic message. Why did you decide to ignore that
>> diagnostic message and ask an abstract question here instead? (And here
>> you don't even mention the diagnostic message.)
>>
>
> OK, I missed this part
>
>> The code I have tried is:
>> sprintf_s(outstring, "Year %3d: %10.2f\n", i, arr[i]);
>
> But my "secondly" still stands.
>

He said "when I try to make use of sprintf_s() (for latest versions of
compilers) it prints nothing". This means that he successfully compiled
and linked the code, and suggests that he might not have seen any
diagnostics. There are ways to make that happen, for instance by
compiling the code in C90 mode while linking to a library containing
sprintf_s().

Re: sprintf_s() syntax?

<t2f5r8$1460$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Mon, 4 Apr 2022 18:19:52 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t2f5r8$1460$1@gioia.aioe.org>
References: <t28beo$u36$1@gioia.aioe.org> <t2drrb$iq4$1@dont-email.me>
<t2druh$iq4$2@dont-email.me> <t2f2bs$ac2$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="37056"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Mon, 4 Apr 2022 16:19 UTC

On 4/4/2022 5:20 PM, James Kuyper wrote:
> On 4/4/22 00:24, Andrey Tarasevich wrote:
>> On 4/3/2022 9:23 PM, Andrey Tarasevich wrote:
>>> On 4/1/2022 7:00 PM, Sams Lara wrote:
>>>> make use of sprintf_s() (for latest versions of compilers) it prints
>>>> nothing so where am I going wrong? I know it is the syntax problem and I
>>>> am stuck with this. The code I have tried is:
>>>
>>> Firstly, I don't see `sprintf_s` in your code. Why are you asking a
>>> question about `sprintf_s` and suppling code that doesn't have
>>> `sprintf_s` in it?
>>>
>>> Secondly, if you simply replaced `sprintf` with `sprintf_s` your code
>>> became invalid. Your compiler clearly told you where the problem is by
>>> issuing a diagnostic message. Why did you decide to ignore that
>>> diagnostic message and ask an abstract question here instead? (And here
>>> you don't even mention the diagnostic message.)
>>>
>>
>> OK, I missed this part
>>
>>> The code I have tried is:
>>> sprintf_s(outstring, "Year %3d: %10.2f\n", i, arr[i]);
>>
>> But my "secondly" still stands.
>>
>
>
> He said "when I try to make use of sprintf_s() (for latest versions of
> compilers) it prints nothing". This means that he successfully compiled
> and linked the code, and suggests that he might not have seen any
> diagnostics. There are ways to make that happen, for instance by
> compiling the code in C90 mode while linking to a library containing
> sprintf_s().

This is close to what happens with the MSVC compiler. I tried it on my
installation, and it gave a bunch of warnings, but it still compiled and
linked the code.
Incidentally, in my case it also prints nothing, but that's obviously UB
in action.

Re: sprintf_s() syntax?

<t2fa2j$g6a$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Mon, 4 Apr 2022 10:32:01 -0700
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <t2fa2j$g6a$1@dont-email.me>
References: <t28beo$u36$1@gioia.aioe.org> <t2drrb$iq4$1@dont-email.me>
<t2druh$iq4$2@dont-email.me> <t2f2bs$ac2$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Apr 2022 17:32:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="498e4a6c32e7e258d7c1a90582db4da1";
logging-data="16586"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xr8H96fHZotjvKNTP/78S"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:bZFikiOJgX7GEsnIxd7ueKysue0=
In-Reply-To: <t2f2bs$ac2$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Mon, 4 Apr 2022 17:32 UTC

On 4/4/2022 8:20 AM, James Kuyper wrote:
> On 4/4/22 00:24, Andrey Tarasevich wrote:
>> On 4/3/2022 9:23 PM, Andrey Tarasevich wrote:
>>> On 4/1/2022 7:00 PM, Sams Lara wrote:
>>>> make use of sprintf_s() (for latest versions of compilers) it prints
>>>> nothing so where am I going wrong? I know it is the syntax problem and I
>>>> am stuck with this. The code I have tried is:
>>>
>>> Firstly, I don't see `sprintf_s` in your code. Why are you asking a
>>> question about `sprintf_s` and suppling code that doesn't have
>>> `sprintf_s` in it?
>>>
>>> Secondly, if you simply replaced `sprintf` with `sprintf_s` your code
>>> became invalid. Your compiler clearly told you where the problem is by
>>> issuing a diagnostic message. Why did you decide to ignore that
>>> diagnostic message and ask an abstract question here instead? (And here
>>> you don't even mention the diagnostic message.)
>>>
>>
>> OK, I missed this part
>>
>>> The code I have tried is:
>>> sprintf_s(outstring, "Year %3d: %10.2f\n", i, arr[i]);
>>
>> But my "secondly" still stands.
>>
>
>
> He said "when I try to make use of sprintf_s() (for latest versions of
> compilers) it prints nothing". This means that he successfully compiled
> and linked the code, and suggests that he might not have seen any
> diagnostics.

Well, that's the problem I'm trying to point out. I'm confident that a
diagnostic message was emitted by the compiler, but he might not have
seen it simply because he wasn't paying attention.

Many C compilers are traditionally/historically configured to report
certain kinds of hard "errors" as "warnings" by default. And this is
often the reason inexperienced users often take careless and dismissive
attitude to such diagnostic messages.

Supplying an argument of incorrect type to a prototyped function is a
hard error in C (http://port70.net/~nsz/c/c11/n1570.html#6.5.2.2p2).

If the diagnostic message is one of those required by the standard (e.g.
a constraint violation), then the code *isn't* officially considered
"successfully compiled and linked". Whatever executable an
implementation produces in such cases is considered a "garbage temporary
output file" the implementation simply "forgot" to clean up after
translation.

--
Best regards,
Andrey Tarasevich

Re: sprintf_s() syntax?

<t2ft10$18v3$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!nOqLI1EbCan+82M4Y2qJhQ.user.46.165.242.91.POSTED!not-for-mail
From: samlara...@gmail.com (Sams Lara)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Mon, 4 Apr 2022 23:49:00 +0100
Organization: Aioe.org NNTP Server
Message-ID: <t2ft10$18v3$1@gioia.aioe.org>
References: <t28beo$u36$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="41955"; posting-host="nOqLI1EbCan+82M4Y2qJhQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Sams Lara - Mon, 4 Apr 2022 22:49 UTC

On 02/04/2022 03:00, Sams Lara wrote:
> Does anybody know how to make use of sprintf_s() for this small function?

Thank you all for the constructive comments and suggestions on this
topic. The program now runs and as you have all noticed that one
parameter was missing that I was stuck with. The Program now runs after
inserting that parameter as suggested by you experts and you can try
this small program, the code is here (3 files - main.c, header file,
functions file). Just input these figures to test it:

10000 1.05 10

<============================================================>
// This is the main Program: main.c
#include <stdio.h>
#include "HelperHeader.h"

int main(void)
{ ��� Investment inv;

��� while (getUserInput(&inv))
��� {
��� ��� inv.invarray[0] = inv.inv0;
��� ��� calculateGrowth(&inv);
��� ��� sendOutput(inv.invarray, inv.years);
��� }
��� return 0;
} <============================================================>
// This is the functions file called functions.c

#include <stdio.h>
#include "HelperHeader.h"

void calculateGrowth(Investment* invp) {
��� for (int i = 1; i < invp->years; i++) {
��� ��� invp->invarray[i] = invp->growth * invp->invarray[i - 1];
��� }
}

int getUserInput(Investment* invp) {
��� int valid;

��� printf("Enter investment, growth rate, number of years (upto %d):
", MAX_YEARS);
��� scanf_s("%lf %lf %d", &(invp->inv0), &(invp->growth), &(invp->years));
��� valid = (invp->inv0 > 0) && (invp->growth > 0) && (invp->years > 0)
&& (invp->years <= MAX_YEARS);

��� printf("Valid input? %d\n", valid);

��� if (!valid) {
��� ��� printf("Invalid Input: exiting.\n");
��� }
��� return valid;
}

void sendOutput(double* arr, int yrs) {
��� char outstring[100];

��� printf("\nRESULTS: \n\n");

��� for (int i = 0; i <= yrs; i++)
��� {
��� ��� sprintf_s(outstring, (unsigned)sizeof(outstring), "Year %3d:�
%10.2f\n", i, arr[i]);

��� ��� // printf("Year %3d:� %10.2f\n", i, arr[i]);
��� ��� printf("%s", outstring);
��� }
��� printf("\n");
} <============================================================>
// This is the header file called: "HelperHeader.h"
#pragma once
#include <stdio.h>

#define MAX_YEARS 100

typedef struct {
��� double inv0;
��� double growth;
��� int years;
��� double invarray[MAX_YEARS + 1];
}Investment;

int getUserInput(Investment* invp);
void calculateGrowth(Investment* invp);
void sendOutput(double* arr, int years);
<============================================================>

Re: sprintf_s() syntax?

<t2gfbe$m1l$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Tue, 5 Apr 2022 00:08:14 -0400
Organization: A noiseless patient Spider
Lines: 86
Message-ID: <t2gfbe$m1l$1@dont-email.me>
References: <t28beo$u36$1@gioia.aioe.org> <t2drrb$iq4$1@dont-email.me>
<t2druh$iq4$2@dont-email.me> <t2f2bs$ac2$1@dont-email.me>
<t2fa2j$g6a$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 5 Apr 2022 04:08:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d593478a494e27b5e4db9a3226098eb3";
logging-data="22581"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PUWF7NuAI53lNnZ5UL5c8L6sYUzLOw7U="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:Djg4y5QejAFQyT14jotE52f42bg=
In-Reply-To: <t2fa2j$g6a$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Tue, 5 Apr 2022 04:08 UTC

On 4/4/22 13:32, Andrey Tarasevich wrote:
> On 4/4/2022 8:20 AM, James Kuyper wrote:
>> On 4/4/22 00:24, Andrey Tarasevich wrote:
>>> On 4/3/2022 9:23 PM, Andrey Tarasevich wrote:
....
>>>> Secondly, if you simply replaced `sprintf` with `sprintf_s` your code
>>>> became invalid. Your compiler clearly told you where the problem is by
>>>> issuing a diagnostic message. Why did you decide to ignore that
>>>> diagnostic message and ask an abstract question here instead? (And here
>>>> you don't even mention the diagnostic message.)
>>>>
>>>
>>> OK, I missed this part
>>>
>>>> The code I have tried is:
>>>> sprintf_s(outstring, "Year %3d: %10.2f\n", i, arr[i]);
>>>
>>> But my "secondly" still stands.
>>>
>>
>>
>> He said "when I try to make use of sprintf_s() (for latest versions of
>> compilers) it prints nothing". This means that he successfully compiled
>> and linked the code, and suggests that he might not have seen any
>> diagnostics.
>
> Well, that's the problem I'm trying to point out. I'm confident that a
> diagnostic message was emitted by the compiler, but he might not have
> seen it simply because he wasn't paying attention.

That's one possibility, but I was pointing out that another possibility
is that no diagnostic message was emitted, due to his choice of compiler
and compilation options.

> Many C compilers are traditionally/historically configured to report
> certain kinds of hard "errors" as "warnings" by default. And this is
> often the reason inexperienced users often take careless and
> dismissive attitude to such diagnostic messages.
>
> Supplying an argument of incorrect type to a prototyped function is a
> hard error in C (http://port70.net/~nsz/c/c11/n1570.html#6.5.2.2p2).

I think "mandatory diagnostic" is a better term than "hard error".
"Hard error" might be misinterpreted as implying that a conforming
implementation of C is required to reject such a program.

I mentioned the possibility that he was compiling in C90 mode, precisely
because C90 didn't have prototypes, and a function could be called
without a declaration in scope - no diagnostic was required.

A compiler option that turns off that mandatory diagnostic would render
it non-conforming to C99 and later, but there's nothing unusual about C
compilers having options that render them non-conforming.

> If the diagnostic message is one of those required by the standard
> (e.g. a constraint violation), then the code *isn't* officially
> considered "successfully compiled and linked".

I consider a program to have been "successfully compiled and linked" if
compilation results in a linkable object file, and if linkage results in
an executable program. The fact that a diagnostic is mandatory does not
prohibit either of those outcomes.

> ... Whatever executable an implementation produces in such cases is
> considered a "garbage temporary output file" the implementation simply
> "forgot" to clean up after translation.

No, in many cases implementations will take code for which a diagnostic
is mandatory, translate it in a way the implementor considers useful,
and generate an executable that will produce that useful behavior when
executed. In some cases, this useful behavior is a documented extension.

Allowing code that calls a undeclared function to be compiled the same
way it would have been in C90 would be an example of such "useful
behavior". Such a program could be linkable with module containing an
external definition for that function, if the types of the function's
parameters declared in the function definition are compatible with the
promoted types of the corresponding function call arguments, and the
return type is `int`.

If I see such a mandatory diagnostic, I wouldn't bother trying to use
the resulting executable, but I know that it's entirely possible that
the resulting executable might actually be executable, and might have
reasonable behavior (not necessarily the behavior I wanted), even though
the standard does not require that this be the case.

Re: sprintf_s() syntax?

<t2nieb$8i6$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: sprintf_s() syntax?
Date: Thu, 7 Apr 2022 13:43:53 -0700
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <t2nieb$8i6$1@dont-email.me>
References: <t28beo$u36$1@gioia.aioe.org> <t2drrb$iq4$1@dont-email.me>
<t2druh$iq4$2@dont-email.me> <t2f2bs$ac2$1@dont-email.me>
<t2fa2j$g6a$1@dont-email.me> <t2gfbe$m1l$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Apr 2022 20:43:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="816ecf34c7a0da40b06e3d2d74dcccac";
logging-data="8774"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19k6KOQomTsQTdx7PxHeZDW"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:TCpernOBkIzLCKfIzWrQMkSFNOM=
In-Reply-To: <t2gfbe$m1l$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Thu, 7 Apr 2022 20:43 UTC

On 4/4/2022 9:08 PM, James Kuyper wrote:
>
>> Many C compilers are traditionally/historically configured to report
>> certain kinds of hard "errors" as "warnings" by default. And this is
>> often the reason inexperienced users often take careless and
>> dismissive attitude to such diagnostic messages.
>>
>> Supplying an argument of incorrect type to a prototyped function is a
>> hard error in C (http://port70.net/~nsz/c/c11/n1570.html#6.5.2.2p2).
>
> I think "mandatory diagnostic" is a better term than "hard error".
> "Hard error" might be misinterpreted as implying that a conforming
> implementation of C is required to reject such a program.

I don't know and, frankly, don't care how someone cam "misinterpret"
something out of the blue. Standard C language does not ever require
rejection, aside perhaps from an active `#error` directive.

>> If the diagnostic message is one of those required by the standard
>> (e.g. a constraint violation), then the code *isn't* officially
>> considered "successfully compiled and linked".
>
> I consider a program to have been "successfully compiled and linked" if
> compilation results in a linkable object file, and if linkage results in
> an executable program. The fact that a diagnostic is mandatory does not
> prohibit either of those outcomes.

I don't. This is like relying on values in uninitialized storage.
Someone might claim that is always "successfuly zero" in their
experiments and even substantiate with some sort of
implementation-specific direct or indirect guarantees, but this is not C.

>> ... Whatever executable an implementation produces in such cases is
>> considered a "garbage temporary output file" the implementation simply
>> "forgot" to clean up after translation.
>
> No, in many cases implementations will take code for which a diagnostic
> is mandatory, translate it in a way the implementor considers useful,
> and generate an executable that will produce that useful behavior when
> executed. In some cases, this useful behavior is a documented extension.

_Only_ when this useful behavior is a documented extension. But even in
that case this still goes beyond C and transgress into the area of some
implementation-specific language. An implementation might even translate
Pascal code as part of their C implementation.

But this is beside the point anyway. This is just pumping smoke into the
topic. We all know what happened in the OP's code. We aren't dealing
with an extension in this case.

> Allowing code that calls a undeclared function to be compiled the same
> way it would have been in C90 would be an example of such "useful
> behavior". Such a program could be linkable with module containing an
> external definition for that function, if the types of the function's
> parameters declared in the function definition are compatible with the
> promoted types of the corresponding function call arguments, and the
> return type is `int`.

This remark is unnecessary, but still: in this case we are dealing with
a variadic function. Even in C90 variadic functions require a prototype
before the call. Calling an unprototyped varidic function leads to
undefined behavior. I does not require a diagnostic, of course, but
still it does not formally result in a useful behavior either.

--
Best regards,
Andrey Tarasevich

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor