编译不同的编译器 [英] compiling on different compilers

查看:77
本文介绍了编译不同的编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一组涉及动态内存的功能

分配。我开始使用gcc然后转移到Pacific C.

原因是我唯一访问gcc是通过ssh

连接我无法访问所有时间,所以我得到了太平洋的b $ b,所以我可以在我的家用Windows电脑上工作。


然后我搬回了gcc,这让我从一些专业中解脱出来错误。

不知怎的太平洋C让我逃脱了完全错误的东西。 gcc立刻给了我分段错误,直到我确定每一件事都是正确的。


gcc是否最适合捕捉错误?如果没有,哪一个是?

I am working on a set of functions that involve dynamic memory
allocation. I started working with gcc and then moved to Pacific C.
The reason was that my only access to gcc was through an ssh
connection that I did not have access to all the time, so I got
Pacific so I could work on my home windows computer.

Then I moved back to gcc, which saved me from some major mistakes.
Somehow Pacific C was letting me get away with stuff that was
completely wrong. gcc immediately gave me segmentation errors until I
got every last thing correct.

Is gcc the best for catching mistakes? If not, which one is?

推荐答案

MJL在12/08/04写道:
MJL wrote on 12/08/04 :
我正在研究一组涉及动态内存分配的函数。我开始使用gcc然后转移到Pacific C.
原因是我唯一访问gcc是通过ssh
连接,我一直无法访问,所以我得到了太平洋,所以我可以在家用Windows电脑上工作。


假设Windows,你可以在家里做同样的事情。 gcc是一个非常常见的用于DJGPP,Mingw,Dev-C ++等的编译器,甚至可以单独用于

命令行。

然后我回到了gcc,这让我免于一些重大错误。
不知何故,太平洋C让我逃脱了完全错误的东西。 gcc立刻给了我分段错误,直到我把最后的事情都弄错了。

gcc是否最适合捕捉错误?如果不是,那是哪一个?
I am working on a set of functions that involve dynamic memory
allocation. I started working with gcc and then moved to Pacific C.
The reason was that my only access to gcc was through an ssh
connection that I did not have access to all the time, so I got
Pacific so I could work on my home windows computer.
Assuming Windows, you can do the same at home. gcc is a very common C
compiler used in DJGPP, Mingw, Dev-C++ etc. or even standalone at
command line.
Then I moved back to gcc, which saved me from some major mistakes.
Somehow Pacific C was letting me get away with stuff that was
completely wrong. gcc immediately gave me segmentation errors until I
got every last thing correct.

Is gcc the best for catching mistakes? If not, which one is?




这很好,但PCLint(仅测试,无编译)更进一步。请注意,

工具不会发现所有错误。

经验丰富的程序员(就像你[/] [将会])一样,没有什么比评论更好。


-

Emmanuel

C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html


C是一个尖锐的工具



It''s good, but PCLint (test only, no compile) goes further. Note that
tools don''t catch all mistakes. There is nothing like a review by an
experienced programmer (like you [are]/[will be]).

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"


Emmanuel Delahaye写道:
Emmanuel Delahaye wrote:
MJL写于12/08/04:
MJL wrote on 12/08/04 :

....剪断...
gcc是否最适合捕捉错误?如果不是,那是哪一个?
.... snip ...
Is gcc the best for catching mistakes? If not, which one is?



这很好,但PCLint(仅测试,无编译)更进一步。注意
工具不会发现所有错误。没有什么比经验丰富的程序员(如[你] / [将会])的评论更好。



It''s good, but PCLint (test only, no compile) goes further. Note
that tools don''t catch all mistakes. There is nothing like a
review by an experienced programmer (like you [are]/[will be]).




夹板(nee lclint)也是好,但仅限于C(没有C ++)。它b / b
也相当便宜。


-

丘吉尔和布什都可以被视为战时领袖,只是<秘书处和埃德先生都是马匹。
。 - 詹姆斯罗德斯。

每次都是对的男人不太可能做得太多。

- Francis Crick,共同发现DNA



splint (nee lclint) is also good, but limited to C (no C++). It
is also considerably cheaper.

--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA


感谢您的信息。


我正在编写一组函数,这些函数在一个链接列表上运行

struct包含一个字符串。我开始按照我的代码最大可移植性的b / b
开始研究它。我发现自从那以后我真的很喜欢使用char *字符串,链接列表,malloc等...


我最大的错误就是被其他人搞砸了编译器是什么

喜欢:


mystruct * pm;


pm =(mystruct *)malloc(sizeof (mystruct *));


应该是:


pm =(mystruct *)malloc(sizeof(mystruct));


我为指针的大小而不是实际的

结构分配内存。


还:


void init(mystruct * pm)

{

pm =(mystruct *)malloc(sizeof(mystruct));

pm-> first = NULL;

pm-> second = NULL;

}


在这里,我试图改变pm指向的内容,而不是指向内存的内容

。当函数返回时,指针

pm仍然指向函数

调用之前指向的内容。


For小例子,一个编译器让我逃脱我的

错误。 gcc导致我的程序每次都给出分段错误错误

,直到我修正了所有错误。再次感谢。


mjl
Thanks for the info.

I am writing a set of functions which operate on a linked list of a
struct which holds a string. I started working on it in the interest
of maximum portability of my code. I have found since that I really
enjoy working with char* strings, linked lists, malloc etc...

My biggest mistake that slipped by that other compiler was something
like:

mystruct* pm;

pm = (mystruct*)malloc(sizeof(mystruct*));

which should have been:

pm = (mystruct*)malloc(sizeof(mystruct));

I was allocating memory for the size of the pointer and not the actual
struct.

also:

void init(mystruct* pm)
{
pm = (mystruct*)malloc(sizeof(mystruct));
pm->first = NULL;
pm->second = NULL;
}

Here I was trying to change what pm pointed to, not the contents of
the memory being pointed to. When the function returned, the pointer
pm still pointed to whatever it was pointing to before the function
call.

For small examples, the one compiler was letting me get away with my
mistakes. gcc caused my program to give the segmentation fault error
every time until I fixed all mistakes. Thanks again.

mjl


这篇关于编译不同的编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆