Re: compiling okay, success running gtk-app computer dependant
- From: Keith Sharp <kms passback co uk>
- To: gtk-app-devel-list gnome org
- Subject: Re: compiling okay, success running gtk-app computer dependant
- Date: Sat, 27 Nov 2004 15:27:53 +0000
On Sat, 2004-11-27 at 15:37 +0100, edward hage wrote:
----------------------------------------
1: // name this program = time.c
2: #include <time.h>
3: #include <gtk/gtk.h>
4:
5: // compiled with: gcc -g time.c -o time `pkg-config gtk+-2.0 --cflags --libs`
6:
7: int main()
8: {
9: struct tm tms;
10: time_t current_time;
11: GDate *date;
12:
13: current_time = time (NULL);
14:
15: tms = *localtime (¤t_time);
16: g_print("time is %d\n", time(NULL));
17:
18: g_date_set_time (date, current_time);
19: g_print("day = %d\n", date->day);
20: return 0;
21: }
---------------------------------------
The problem does not appear when I do not define tms (blank line 9 and 15)!! But the
problem is that in my 'real' program I want to use both tms and current_time.
The segmentation fault occurs after that the first line is printed. So this must be at
g_date_set_time.
The big question is in my view: Is it a bug in glib / g_date_set_time that it can not deal
with tms being defined or someting that is not okay with my computer?
I think the problem is that localtime(3) returns a pointer to a
statically allocated tm struct. You should change line 9 to read:
struct tm *tms;
and line 15 to read:
tms = localtime (¤t_time);
With these changes your program works on my Fedora Core 2 system.
Without the changes, your original code, I get a segmentation fault.
Keith.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]