public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* About ' * ' not recognized
@ 2023-01-21  1:04 naoki ueda
  2023-01-21  1:12 ` Andrew Pinski
  0 siblings, 1 reply; 3+ messages in thread
From: naoki ueda @ 2023-01-21  1:04 UTC (permalink / raw)
  To: gcc-bugs

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

When I tried to execute the attached file mycalc.c with a command line
argument, it could not be executed normally only in the case of '*'.
'+', '-' and '/' can be executed normally, but the compiler cannot
execute '*' normally. Isn't this a gcc bug?


~/Clearning$ ./mycalc 20 * 30
用法:mycalc 数値1 演算子 数値2

[-- Attachment #2: mycalc.c --]
[-- Type: text/x-csrc, Size: 929 bytes --]

#include <stdio.h>
#include <stdlib.h>             // for exit()
#include <string.h>             // for strcpy() strlen()
int main(int argc, char *argv[])
{
     double d1, d2,ans;
     char ope[80];
     
     if (argc != 4) {
          printf("用法:mycalc 数値1 演算子 数値2\n");
          exit(1);
     }
     d1 = atof(argv[1]);
     d2 = atof(argv[3]);
     strcpy(ope,argv[2]);
     if (strlen(ope) != 1) {
          printf("演算子が1文字でない\n");
          exit(1);
     }
     switch (ope[0]) {
     case '+':
          ans = d1 + d2;
          break;
     case '-':
          ans = d1 - d2;
          break;
     case '*':
          ans = d1 * d2;
          break;
     case '/':
          if (d2 == 0.0) ans = 0.0;    // 0除算対応
          else ans = d1 / d2;
          break;
     default:
          printf("演算子が違っている\n");
          exit(1);
     }
     printf("%f\n",ans);
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: About ' * ' not recognized
  2023-01-21  1:04 About ' * ' not recognized naoki ueda
@ 2023-01-21  1:12 ` Andrew Pinski
  2023-01-21  1:18   ` naoki ueda
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2023-01-21  1:12 UTC (permalink / raw)
  To: naoki ueda; +Cc: gcc-bugs

On Fri, Jan 20, 2023 at 5:05 PM naoki ueda via Gcc-bugs
<gcc-bugs@gcc.gnu.org> wrote:
>
> When I tried to execute the attached file mycalc.c with a command line
> argument, it could not be executed normally only in the case of '*'.
> '+', '-' and '/' can be executed normally, but the compiler cannot
> execute '*' normally. Isn't this a gcc bug?

First off this email list is really for automated messages from gcc's
bugzilla rather than from users reporting issues.

>
>
> ~/Clearning$ ./mycalc 20 * 30

Oh * here is being handled by the shell you are using and being
expanded as all the files in the current working directory. This has
nothing to do with GCC really.
You can use quotes around the * to force the shell not expanding it
such as this:
./mycalc 20 '*' 30

or you use \ to force the shell not to expand what comes after the * like this:
./mycalc 20 \* 30

Thanks,
Andrew Pinski

> 用法:mycalc 数値1 演算子 数値2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: About ' * ' not recognized
  2023-01-21  1:12 ` Andrew Pinski
@ 2023-01-21  1:18   ` naoki ueda
  0 siblings, 0 replies; 3+ messages in thread
From: naoki ueda @ 2023-01-21  1:18 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-bugs

[-- Attachment #1: Type: text/plain, Size: 1103 bytes --]

Ok, I see.

2023年1月21日(土) 10:12 Andrew Pinski <pinskia@gmail.com>:

> On Fri, Jan 20, 2023 at 5:05 PM naoki ueda via Gcc-bugs
> <gcc-bugs@gcc.gnu.org> wrote:
> >
> > When I tried to execute the attached file mycalc.c with a command line
> > argument, it could not be executed normally only in the case of '*'.
> > '+', '-' and '/' can be executed normally, but the compiler cannot
> > execute '*' normally. Isn't this a gcc bug?
>
> First off this email list is really for automated messages from gcc's
> bugzilla rather than from users reporting issues.
>
> >
> >
> > ~/Clearning$ ./mycalc 20 * 30
>
> Oh * here is being handled by the shell you are using and being
> expanded as all the files in the current working directory. This has
> nothing to do with GCC really.
> You can use quotes around the * to force the shell not expanding it
> such as this:
> ./mycalc 20 '*' 30
>
> or you use \ to force the shell not to expand what comes after the * like
> this:
> ./mycalc 20 \* 30
>
> Thanks,
> Andrew Pinski
>
> > 用法:mycalc 数値1 演算子 数値2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-21  1:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21  1:04 About ' * ' not recognized naoki ueda
2023-01-21  1:12 ` Andrew Pinski
2023-01-21  1:18   ` naoki ueda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).