English 中文(简体)
《刑法》在用这些旗帜编纂时没有执行。
原标题:Code fails to execute when compiled with these flags
  • 时间:2011-10-04 13:23:49
  •  标签:
  • c

My code is trying to find the entropy of a signal (stored in data and interframe - in the full code these would contain the signal, here I ve just put in some random values). When I compile with gcc temp.c it compiles and runs fine. Output:

entropy: 40.174477
features: 0022FD06
features[0]: 40
entropy: 40

但是,当我用快乐——最快的————我们——智慧——来汇编时,它汇编了材料,但没有执行第48条。 它需要拥有所有四条旗帜才能失败,其中三条是罚款。

这部法典可能看起来是 we的——我只把失败的比喻排除在一个更大的方案之外。 我只想到编造者旗帜是什么,有人把他们带进去(他们通常更多),但我发现这些是坏的。

一切帮助都受到高度赞赏。

#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include <math.h>

static void calc_entropy(volatile int16_t *features, const int16_t* data,
const int16_t* interframe, int frame_length);


int main()
{
    int frame_length = 128;
    int16_t data[128] = {1, 2, 3, 4};
    int16_t interframe[128] = {1, 1, 1};

    int16_t a = 0;
    int16_t* features = &a;

    calc_entropy(features, data, interframe, frame_length);
    features += 1;

    fprintf(stderr, "
entropy: %d", a);

    return 0;
}

static void calc_entropy(volatile int16_t *features, const int16_t* data,
const int16_t* interframe, int frame_length)
{
    float histo[65536] = {0};
    float* histo_zero = histo + 32768;
    volatile float entropy = 0.0f;
    int i;

    for(i=0; i<frame_length; i++){
        histo_zero[data[i]]++;
        histo_zero[interframe[i]]++;
    }

    for(i=-32768; i < 32768; i++){
        if(histo_zero[i])
            entropy -= histo_zero[i]*logf(histo_zero[i]/(float)(frame_length*2));
    }

    fprintf(stderr, "
entropy: %f", entropy);

    fprintf(stderr, "
features: %p", features);
    features[0] = entropy; //execution fails here
    fprintf(stderr, "
features[0]: %d", features[0]);
}

Edit: I m 采用4.5.2, 并配有x86 结构。 而且,如果我汇编和操作虚拟局(gcc -lm -mstackrealign -msse -Os -ftree-vectorize temp.c),它就执行得当。

Edit2:我获得治疗

entropy: 40.174477
features: 00000000

然后,窗口发出的信息告诉我,该方案已经停止。

Edit3: In the five months since I originally posted the question I ve updated to gcc 4.7.0, and the code now runs fine. I went back to gcc 4.5.2, and it failed. Still don t know why!

问题回答
ottavio@magritte:/tmp$ gcc x.c -o x -lm -mstackrealign -msse -Os -ftree-vectorize
ottavio@magritte:/tmp$ ./x 

entropy: 40.174477
features: 0x7fff5fe151ce
features[0]: 40
entropy: 40
ottavio@magritte;/tmp$ gcc x.c -o x -lm
ottavio@magritte:/tmp$ ./x 

entropy: 40.174477
features: 0x7fffd7eff73e
features[0]: 40
entropy: 40
ottavio@magritte:/tmp$

因此,它有什么错误? gcc 4.6.1和x86_64架构。

这似乎也在这里发生,我看到唯一可能不可靠的事情是,你正在取得16个比值(名称)和转换32个比值(热带)。

features[0] = entropy; //execution fails here

这当然会使其失去价值。

顺便提一下,但对于它来说,如果将你的内在价值改变为t32_t值,则看看它是否发挥了任何作用。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签