Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: OO method wont parse

by afoken (Chancellor)
on Aug 29, 2017 at 05:53 UTC ( [id://1198244]=note: print w/replies, xml ) Need Help??


in reply to Re: OO method wont parse
in thread OO method wont parse

You don't have to group variable declarations all at the beginning of a block, as we used to do in C. (I believe that was because they needed to be allocated on the stack by the compiler.) Declare variables when you're about to use them.

Just a little bit of bean counting: C99 allows to declare variables where you need them. Today's C compilers have become smart enough. Here's a silly example:

/tmp>cat c99.c #include <stdio.h> #include <string.h> int main(int argc, char ** argv) { char buf1[10]; snprintf(buf1,sizeof(buf1),"%d",argc); int n=0; for (int i=0; i<argc; i++) { int len=strlen(argv[i]); len++; n+=len; } char buf2[10]; snprintf(buf2,sizeof(buf2),"%d",n); char buf3[80]; snprintf(buf3,sizeof(buf3),"%s args using %s bytes",buf1,buf2) +; puts(buf3); return 0; } /tmp>CFLAGS="-std=c99 -pedantic -Wall" make c99 cc -std=c99 -pedantic -Wall c99.c -o c99 /tmp>./c99 foo bar baz 4 args using 18 bytes /tmp>

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: OO method wont parse
by talexb (Chancellor) on Aug 29, 2017 at 15:05 UTC

    Thanks -- my experience in this matter comes from looking at the output from a VMS cross-compiler that generated 68000 assembler in the mid-80's. I imagined that this shortcoming would have been solved since then. :)

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      my experience in this matter comes from looking at the output from a VMS cross-compiler that generated 68000 assembler in the mid-80's. I imagined that this shortcoming would have been solved since then

      I use C99 in my daily job, since about two years. C99 is an improvement over C89 (ANSI C), yes. And it looks like C11 improves even more. (C11 is not supported by our legacy build environment.) But my wish list for a better C standard becomes longer every day. It's hard to use C after using Perl for years. You get used to have a lot of stuff done automatically for you, and being forced to do that manually again is annoying. Especially when you know that the computer could do that for you, if only the compiler and the runtime environment were a little bit smarter.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1198244]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-18 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found