我計劃休息一個完全不相關的線分段錯誤,在這裏給出了EXC_BAD_ACCESS,根據堆棧跟蹤在Xcode:行導致對代碼
int main (int argc, const char * argv[]) {
float usd,btc,bid,ask,order_price,possible_price;
DateData * prices = load_prices(); <---
DateData * load_prices(){
FILE * file = fopen("price.dat", "rb"); <---
我確定這有沒有關係該代碼行,但後面的一行。在稍後不調用的函數中,有一行代碼似乎破壞了程序。當它在執行行之前從函數返回時,程序沒有這個問題,但是如果它應該從行之後的函數返回,則會出現此問題。
代碼行是對OpenCL的調用。它以某種方式破壞該程序?
err = clEnqueueReadBuffer(ocl_data->commands, ocl_data->output, CL_TRUE, 0, sizeof(CombinationResult) * PPO_COMBINATIONS, (*PPO_results)[x] + PPO_COMBINATIONS*(p + 5), 0, NULL, NULL);
PPO_COMBINATIONS被定義爲整數的宏和PPO_results的類型是CombinationResult(*)[3] [PPO_COMBINATIONS * 11]。 ocl_data->命令的類型爲cl_command_queue,ocl_data-> output的類型爲cl_mem。 err,p和x的類型爲int。
我正在使用Xcode和「Apple LLVM Compiler 3.0」。出於某種原因,「LLVM GCC 4.2」編譯器給出了「架構i386的格式錯誤的元數據記錄」。
這是使用命令行編譯並用gdb運行時的結果:
Matthew-Mitchell:Parrallel BitCoin Trading Algorithm matt$ gcc -g cmain.c -o test -lcurl -framework OpenCL -std=c99 -arch i386
Matthew-Mitchell:Parrallel BitCoin Trading Algorithm matt$ gdb testGNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 15 16:03:10 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .... done
(gdb) run
Starting program: /Users/matt/Programming/Bit Coin algorithm/Parrallel BitCoin Trading Algorithm/test
Reading symbols for shared libraries .+++.................................................................. done
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0xbea7d7cc
0x00003e9a in main (argc=0, argv=0x1000) at cmain.c:572
572 int main (int argc, const char * argv[]) {
當在命令行直接運行該程序立即退出。
你可以在'gdb'程序崩潰後發佈'bt'的輸出嗎? – 2012-04-08 16:38:07
你有沒有在例如Valgrind的? – 2012-04-08 16:40:33
你嘗試沒有'const'在'main'第二放慢參數? [C99標準](http://www.open-std.org/JTC1/sc22/wg14/www/docs/n1256.pdf)將其定義爲簡單的'char **'... – pmg 2012-04-08 16:55:41