GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 17, 2014 9:51 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: g_print versus printf
PostPosted: Sat Apr 21, 2007 11:18 am 
Offline
Familiar Face

Joined: Sat Apr 21, 2007 11:09 am
Posts: 8
Location: Melbourne
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)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 21, 2007 2:42 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
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.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 21, 2007 3:49 pm 
Offline
Familiar Face

Joined: Sat Apr 21, 2007 11:09 am
Posts: 8
Location: Melbourne
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 21, 2007 11:18 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
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.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 4:37 am 
Offline
Familiar Face

Joined: Sat Apr 21, 2007 11:09 am
Posts: 8
Location: Melbourne
Thanks very much for your assistance!!!

Regards,
Jason.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group