GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

g_print versus printf

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
jasonkb
Familiar Face


Joined: 21 Apr 2007
Posts: 8
Location: Melbourne

PostPosted: Sat Apr 21, 2007 11:18 am    Post subject: g_print versus printf Reply with quote

Was wondering why printf() will not work until the application shuts down, but g_print() will work anytime? Is there something in GTK+ that blocks console output? Does GTK+ block any other C standard library functions or block any UNIX standards?

I tried to contrust a directory and set user permissions from the C program using libs from <sys/stat.h> and that worked fine during the app. So why does printf() not work?

PS- I'm not annoyed at this, it's mainly a question out of curiosity because similar things happen in other GUI toolkits for C++ like wx or Qt. THere seems to be something in the architecture that I find interesting and wanted to know why. (I'm a Java developer and got used to System.out.println to debug apps)

Interested for replies by anyone!

Regards- Jason
(native language noob)
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Sat Apr 21, 2007 2:42 pm    Post subject: Reply with quote

You are right; GLib does block printf() from executing until the end of your application. This is due to how the main loop works. GLib provides a number of message logging functions such as g_print, g_message, g_critical, and g_warning. g_printf is also provided if you include <glib/gstdio.h>. It all comes down to the main loop function, which blocks printf because of how it is designed. However, if you are designing a GTK+ application, you can just use GLib's message functions.
Back to top
jasonkb
Familiar Face


Joined: 21 Apr 2007
Posts: 8
Location: Melbourne

PostPosted: Sat Apr 21, 2007 3:49 pm    Post subject: Reply with quote

Thankyou very much for explaining this to me. I feel much happier now I know what was causing that behaviour.

I noticed you had placed a <glib/gstdio.h> include statement. That suggests that the normal stdio.h is affected by the event loop. Does this mean that scanf etc will not work? Are there any other C standards affected by this? More importantly will this affect the standard Unix system calls?

Sorry for asking so many questions as I am a complete stranger to native language programming.

Final question: will this event loop prevent me from using 3rd party libraries for C/C++? I was hoping to use sound libraries and xml libraries but if nothing executes untill the program terminates the event loop...

It looks as though I will have much experimenting to do! I must say though I like the simplicity of the GTK+ API. Seems very structured when using it in conjuction with C making it nice and simple to follow the program state. Warrants giving it a good try.

thanks again.

Jason.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Sat Apr 21, 2007 11:18 pm    Post subject: Reply with quote

As to your stdio.h question, it really all depends on the function. Generally, when using GTK+, you should use the GLib wrapper functions if available because they are cross-platform.

The loop affects standard output, but you are fine beyond that. I haven't found any external libraries that have been affected by this. You should be fine using most libraries.
Back to top
jasonkb
Familiar Face


Joined: 21 Apr 2007
Posts: 8
Location: Melbourne

PostPosted: Sun Apr 22, 2007 4:37 am    Post subject: Reply with quote

Thanks very much for your assistance!!!

Regards,
Jason.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP