Vim Tips Wiki
No edit summary
 
(Change <tt> to <code>, perhaps also minor tweak.)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{Dodgy|This is only useful in junk programs with simple functions. Also, it shows the return value, not "what it's printing out".}}
{{review}}
 
  +
{{TipImported
{{Tip
 
 
|id=1436
 
|id=1436
  +
|previous=1435
|title=wrap function calls in a print statement
 
  +
|next=1437
|created=December 8, 2006 15:40
+
|created=2006
 
|complexity=advanced
 
|complexity=advanced
 
|author=Peter Jenkins
 
|author=Peter Jenkins
 
|version=5.7
 
|version=5.7
 
|rating=68/24
 
|rating=68/24
  +
|category1=
|text=
 
  +
|category2=
warning: i couldn't get this to work except by entering the commands, maybe there is a way to get the let statement to work but for me it has problems with the quotes. I couldn't figure out a way to properly escape them.
 
 
}}
 
warning: i couldn't get this to work except by entering the commands, maybe there is a way to get the let statement to work but for me it has problems with the quotes. I couldn't figure out a way to properly escape them.
   
 
have you ever had a function in C: doSomething(a, b, c); and you want to see what it's printing out? this wraps that function so the output looks like this:
   
  +
<pre>
 
doSomething(a,b,c): 37
  +
</pre>
   
 
c for it looks like <code>printf("doSomething(a,b,c): \"%s\"\n", doSomething(a,b,c));</code>
have you ever had a function in C: doSomething(a, b, c); and you want to see what it's printing out? this wraps that function so the output looks like this:
 
   
 
kind of a pain to type often. i also try to make it so the cursor ends up over the s so that you can replace it with d, etc for printing things other than strings. again, this works if you type in the commands as they are depicted, but not with the let statement. if you want to do it by hand, do something like qt (to assign it to "t"). then type what's in between the quotes, starting with 0.
   
  +
<pre>
 
:let @a = "0f(byt;iprintf("^[pa: "~@kb\"%s\"\n", ^[$i)^[?%^Ml^]"
  +
</pre>
   
 
==Comments==
doSomething(a,b,c): 37
 
  +
You should use a debugger for this sort of operation.
   
 
 
c for it looks like printf("doSomething(a,b,c): \"%s\"\n", doSomething(a,b,c));
 
 
 
 
kind of a pain to type often. i also try to make it so the cursor ends up over the s so that you can replace it with d, etc for printing things other than strings. again, this works if you type in the commands as they are depicted, but not with the let statement. if you want to do it by hand, do something like qt (to assign it to "t"). then type what's in between the quotes, starting with 0.
 
 
 
 
 
 
:let @a = "0f(byt;iprintf("^[pa: "~@kb\"%s\"\n", ^[$i)^[?%^Ml^]"
 
 
 
 
 
}}
 
 
== Comments ==
 
An alternative would be to become a real programmer instead of a code-monkey and learn how to use a debugger; that's exactly the use-case of debuggers. But of course, the so called "programmers" or "developers" of today don't need the help of such arcane tools because they are agile and whatnot.
 
 
'''Anonymous'''
 
, December 9, 2006 2:29
 
 
----
 
----
 
In fact, you can define
I know how to use a debugger, thank you. Sometimes a debugger is more overhead than I want to deal with.
 
  +
<pre>
 
 
#define hcffl printf("\n= [ %s : %s : %d ] =", \
Pete Jenkins
 
 
__FILE__,__FUNCTION__,__LINE__ \
, December 10, 2006 10:58
 
 
); fflush(stdout);
----
 
  +
</pre>
In fact, you can define
 
 
&#35;define hcffl fprintf(stdout,"\n= [ %s : %s : %d ] =", \
 
__FILE__,__FUNCTION__,__LINE__ \
 
); fflush(stdout);
 
 
then, add
 
 
hcffl;
 
   
 
then, add
every where you need, and
 
  +
<pre>
 
hcffl;
  +
</pre>
   
 
every where you need, and
&#35;define hcffl ;
 
  +
<pre>
 
#define hcffl ;
  +
</pre>
   
to remove all these fprintf when make release version
+
to remove all these printf when make release version.
   
huangchao--AT--hotmail.com
 
, January 23, 2007 0:41
 
 
----
 
----
<!-- parsed by vimtips.py in 0.831821 seconds-->
 

Latest revision as of 06:25, 13 July 2012

Tip 1436 Printable Monobook Previous Next

created 2006 · complexity advanced · author Peter Jenkins · version 5.7


warning: i couldn't get this to work except by entering the commands, maybe there is a way to get the let statement to work but for me it has problems with the quotes. I couldn't figure out a way to properly escape them.

have you ever had a function in C: doSomething(a, b, c); and you want to see what it's printing out? this wraps that function so the output looks like this:

doSomething(a,b,c): 37

c for it looks like printf("doSomething(a,b,c): \"%s\"\n", doSomething(a,b,c));

kind of a pain to type often. i also try to make it so the cursor ends up over the s so that you can replace it with d, etc for printing things other than strings. again, this works if you type in the commands as they are depicted, but not with the let statement. if you want to do it by hand, do something like qt (to assign it to "t"). then type what's in between the quotes, starting with 0.

:let @a = "0f(byt;iprintf("^[pa: "~@kb\"%s\"\n", ^[$i)^[?%^Ml^]"

Comments[]

You should use a debugger for this sort of operation.


In fact, you can define

#define hcffl printf("\n= [ %s : %s : %d ] =", \
 __FILE__,__FUNCTION__,__LINE__ \
 ); fflush(stdout);

then, add

hcffl;

every where you need, and

#define hcffl ;

to remove all these printf when make release version.