我在writeLogs
例程中遇到了段错误。
(gdb) print *analyzers->analyzer2.log
Cannot access memory at address 0x80000007f5b4
(gdb) print analyzers->analyzer2.log
$13 = (int *) 0x80000007f5b4
所以,指针似乎存在,价值,而不是。 我希望,我在每个例程中都有相同的指针和相同的值,我称之为。见 附加代码:
typedef struct analyzer_t
{
int *log;
}analyzer_t;
typedef struct analyzers_t
{
analyzer_t analyzer2;
}analyzers_t;
int MarketTalkMessagesVerarbeiten(unsigned char *datap, size_t size, GTree* t, analyzers_t *analyzers)
{
*analyzers->analyzer2.log++;
}
int writeLogs(char *name, analyzers_t *analyzers)
{
printf("Anal: %d\n", *analyzers->analyzer2.log );
}
gboolean main_loop(mainloop_param_t *data)
{
analyzers_t *analyzers = data->analyzers;
MarketTalkMessagesVerarbeiten(pUncompressStreamData, sizeBMB, t, analyzers);
writeLogs(namelist[i]->d_name, analyzers);
}
int main()
{
int log_a2 = 0;
analyzers_t analyzers;
analyzers.analyzer2.log = &log_a2;
mainloop_param_t mlparams;
mlparams.analyzers = &analyzers;
GMainLoop* loop = g_main_loop_new (NULL, FALSE);
g_timeout_add (5000, (GSourceFunc)main_loop, &mlparams);
g_main_loop_run (loop);
}
答案 0 :(得分:2)
++
比*
更紧密。
所以
*analyzers->analyzer2.log++;
...log
(一个指针!)要增加...log
指向的位置,请执行:
(*analyzers->analyzer2.log)++;
那是:
analyzers->analyzer2.log