Re: goto



On Thu, 16 Jul 2009 06:29:12 +0200, "io_x" <a@xxxxxxxxxxx> wrote:

yesterday i wrote one routine, so you can examine that:

[snip original code]

Here is a rewrite that eliminates the gotos and the "silly" macros. There
is no guarantee that it (or the original code) is correct. Some people
have a twisted panties problem with do/while blocks. In this case they are
easily recoded and I leave the joy of doing so to anyone who might care.

int getStdI(char* tmp, int sztmp)
{
int i, r, c;
char *a;

if(tmp==0||sztmp<=1) return 0;
*tmp=0; c=0;

do {
Fflush_m(stdout_m);
i=fgets_m(tmp, sztmp, stdin_m); /* i=strlen(tmp) */
if((i<=0) || (i+1==sztmp)) { /* errore di input */
if(++c>=3) return 0;
P("Stringa Troppo lunga o Errore hardware\nreturneinserire > ");
Fflush_m(stdin_m);
continue;
}
} while(0);

a=tmp+i; r=i;
do {
if(a<=tmp) break;
--a;
if (!((*a==10)||(*a==13)||(Isspace_m(*a))) break;
*a=0; --r;
} while(1);
return r;
}

Richard Harter, cri@xxxxxxxx
http://home.tiac.net/~cri, http://www.varinoma.com
If I do not see as far as others, it is because
I stand in the footprints of giants.
.



Relevant Pages

  • Re: goto
    ... is no guarantee that it (or the original code) is correct. ... I've never heard an objection to them. ... int getStdI ...
    (comp.lang.c)
  • Re: Problems with mex file (allocating memory? )
    ... Here is a section of your original code you posted: ... int *maxNoOfPhotons; ... Or should you just return to MATLAB at that point with an error message? ...
    (comp.soft-sys.matlab)
  • Re: splice: move balance_dirty_pages_ratelimited() outside of splice actor
    ... I think such macros are horribly ugly and that the original code ... I think the macros are pretty foul too (perhaps we should migrate it to ... particular helper like this does, the code becomes more readable, more ...
    (Linux-Kernel)
  • Re: Could anyone explain the code for me?
    ... The original code is from line 328 to 380. ... > Missing semi-colon after struct definition. ... > understand macros, and should be using functions instead. ... It is really confusing. ...
    (comp.lang.cpp)
  • Re: Explain why this prints the same
    ... > his original code and cleaned it up, but I am still wondering about ... lying to the compiler. ... Here the result is certain to be undefined behaviour. ...
    (comp.lang.c)

Loading