compiler-construction

How exactly keyword 'params' work?

拜拜、爱过 提交于 2021-02-16 07:49:10
问题 The following code sample prints: T T[] T[] While first two lines are as expected, why compiler selected param array for a regular array? public class A { public void Print<T>(T t) { Console.WriteLine("T"); } public void Print<T>(params T[] t) { Console.WriteLine("T[]"); } } class Program { static void Main(string[] args) { A a = new A(); a.Print("string"); a.Print("string","string"); a.Print(new string[] {"a","b"}); } } 回答1: Under the hood a.Print("string","string"); is just syntactic sugar

'cl' is not recognized as an internal or external command

 ̄綄美尐妖づ 提交于 2021-02-15 05:50:22
问题 Below is the error message when I run "scons" to compiler in windows7: ----------------------------------------------------------------------------------- 'cl' is not recognized as an internal or external command, operable program or batch file. scons: *** [out\windows-x86-MD-unicode-vs2008-rel\obj-static\src\featuresets\ada pters\im-history\AddToChatRoomHistoryVisitor.obj] Error 1 scons: building terminated because of errors. ------------------------------------------------------------------

Problem to compile a C-program by GCC with GD2 library installed via MacPorts

两盒软妹~` 提交于 2021-02-11 12:50:37
问题 I have successfully compiled a C-program by GCC on Mac with GD2 library installed directly from sources. Now I am trying to do that with GD2 library installed via MacPorts and have the following error message: plotgeometry.c:5:16: error: gd.h: No such file or directory plotgeometry.c: In function 'PlotGeometry': plotgeometry.c:28: error: 'gdImagePtr' undeclared (first use in this function) plotgeometry.c:28: error: (Each undeclared identifier is reported only once plotgeometry.c:28: error:

Problem to compile a C-program by GCC with GD2 library installed via MacPorts

Deadly 提交于 2021-02-11 12:50:08
问题 I have successfully compiled a C-program by GCC on Mac with GD2 library installed directly from sources. Now I am trying to do that with GD2 library installed via MacPorts and have the following error message: plotgeometry.c:5:16: error: gd.h: No such file or directory plotgeometry.c: In function 'PlotGeometry': plotgeometry.c:28: error: 'gdImagePtr' undeclared (first use in this function) plotgeometry.c:28: error: (Each undeclared identifier is reported only once plotgeometry.c:28: error:

Should we prefer temporary variables over user defined variables in c++

梦想与她 提交于 2021-02-09 08:44:27
问题 Lets say there is a c++ function foo() which returns a boolean. I call this functions to check the status of a property Or to get the result of the function call. So what would be the best way to call this type of functions. Method 1 : bool flag = foo() if (flag) { // some code } else { // else some code } Method 2: if ( foo() ) { // some code } else { // some code } My Question : Does using the temporary variable gives compiler opportunity to better optimize in general. 回答1: First of all,

Will the compiler exclude unused template code?

我的未来我决定 提交于 2021-02-08 14:00:27
问题 When you use a template with numerous methods (like vector) and compile your code, will the compiler discard the code from the unused methods? 回答1: A template is not instantiated unless it is used, so there is actually no code to discard. The standard says (14.7.1/10) An implementation shall not implicitly instantiate a function template, a member template, a non-virtual member function, a member class, or a static data member of a class template that does not require instantiation. It is

How to make a cross compiler using gcc?

淺唱寂寞╮ 提交于 2021-02-08 12:12:40
问题 Though there are many tutorials online on how to make a cross compiler, I am actually not getting it. I am using fedora 16 and already have gcc installed. I am not sure about binutils . How do I make a cross compiler for my own OS (the target) ? I was reading here on os dev wiki but I don't get it. I mean, what do I do ? I just don't follow there steps. Note : I want to build a cross compiler for the same architecture I am currently working on.I mean the same architecture that is running

How to make a cross compiler using gcc?

泄露秘密 提交于 2021-02-08 12:10:13
问题 Though there are many tutorials online on how to make a cross compiler, I am actually not getting it. I am using fedora 16 and already have gcc installed. I am not sure about binutils . How do I make a cross compiler for my own OS (the target) ? I was reading here on os dev wiki but I don't get it. I mean, what do I do ? I just don't follow there steps. Note : I want to build a cross compiler for the same architecture I am currently working on.I mean the same architecture that is running

Why are two class files created on compiling?

柔情痞子 提交于 2021-02-08 10:26:09
问题 I knew that when a class has an inner class then this class will be compiled to two class files. Today I have codes as below public class GenericDeserializer { public static void main(String[] args) { String cityPageLoadJson = "{\"count\":2,\"pageLoad\":[{\"id\":4,\"name\":\"HAN\"},{\"id\":8,\"name\":\"SGN\"}]}"; Type type = new TypeToken<GenericResult<City>>() { }.getType(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); GenericResult<City> cityPageLoad = gson.fromJson

Shift Reduce Conflict for arithmetic expressions in yacc

别来无恙 提交于 2021-02-08 08:30:40
问题 This grammar has given me conflict despite specifying precedence of operators. Even in the Dragon book it's been resolved in such a way(the way implemented as first 7 lines below) but it still gets conflict! Below is the code implemented in yacc %right THEN_KW %right ELSE_KW %left XOR_KW OR_KW %right '=' %left AND_KW ALSO_KW %left EQ_KW LT_KW GT_KW LE_KW GE_KW %left PLUS_KW MINUS_KW %left MULT_KW DIV_KW MOD_KW %right NOT_KW arthlogicexpr -> operand | arthlogicexpr arthop arthlogicexpr arthop