pkarashchenko commented on pull request #1108:
URL: 
https://github.com/apache/incubator-nuttx-apps/pull/1108#issuecomment-1081777521


   > > I just briefly searched in the code and see that `optind++;` is used in 
many places. Taking into account that `#define optind (*(getoptindp()))` this 
becomes a useless and all the code that is relying on `optind` after `optind++` 
is executed wrongly.
   > 
   > `optind++` is good usage to access the argument after option. The problem 
here is that quickjs parse the argument by self and doesn't use getopt at all, 
but the local variable definition conflict with optind unintentionally.
   
   @xiaoxiang781216 I'm talking not about the problem here. The author solves 
it by renaming of a variable.
   The case is that in Linux (https://linux.die.net/man/3/optind) the `optind` 
is `int optind` and referenced via `extern int optind`, but in NuttX it is `FAR 
int *getoptindp(void);  /* Index into argv */` and `#define optind 
(*(getoptindp()))` so `optind++;` does not increment the index holder.
   Please try to run a small example locally
   ```
   #include <stdio.h>
   
   #define optind (*(getoptindp()))
   
   int *getoptindp(void)
   {
       static int a;
       return &a;
   }
   
   int main()
   {
       printf("Test: %d, %d", optind++, optind);
   
       return 0;
   }
   ```
   and you will see that zero is printed two times.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to