recursion

PC-Lint needs a list of all include paths for the files to be scanned. How to get a list of all include paths recursively needed by a target in CMake?

爱⌒轻易说出口 提交于 2020-06-13 06:24:31
问题 I'm in a project where CMake is used for managing the build process. In the project there are several executables which depends on components and these components are built as static libraries. There are also dependencies between these components. For each executable or component, only their own local includes are specified and includes from dependencies are resolved by using target_link_libraries(<target> <dependencies>) . So far so good. The problem is when PC-Lint shall be integrated into

Recursive computation using variable templates - gcc vs clang

非 Y 不嫁゛ 提交于 2020-06-11 16:53:09
问题 Consider the following example: #include <cstdio> template <int N> int fib = fib<N - 1> + fib<N - 2>; template <> int fib<2> = 1; template <> int fib<1> = 1; int main() { std::printf("%d %d %d", fib<4>, fib<5>, fib<6>); } GCC 7.x, 8.x, 9.x, and 10.x all print out the expected result of 3 5 8 . Clang 5.x, 6.x, 7.x, 8.x, 9.x, and 10.x all print out 1 3 4 as a result. live example on godbolt.org Clang's behavior is surprising. Is there any subtle interaction between variable template

g++ and clang++ different behaviour with recursive initialization of a static member

僤鯓⒐⒋嵵緔 提交于 2020-06-11 16:09:54
问题 Given the following code: #include <iostream> template <std::size_t N> struct foo { static std::size_t value; }; template <> std::size_t foo<0>::value = 0u; template <size_t N> std::size_t foo<N>::value = 1u + foo<N - 1u>::value; int main() { std::cout << foo<3u>::value << ' ' << foo<2u>::value << ' ' << foo<1u>::value << ' ' << foo<0u>::value << std::endl; } where the static member value of the template struct foo is recursively initialized, I get different outputs from g++: 3 2 1 0 and from

g++ and clang++ different behaviour with recursive initialization of a static member

最后都变了- 提交于 2020-06-11 16:06:08
问题 Given the following code: #include <iostream> template <std::size_t N> struct foo { static std::size_t value; }; template <> std::size_t foo<0>::value = 0u; template <size_t N> std::size_t foo<N>::value = 1u + foo<N - 1u>::value; int main() { std::cout << foo<3u>::value << ' ' << foo<2u>::value << ' ' << foo<1u>::value << ' ' << foo<0u>::value << std::endl; } where the static member value of the template struct foo is recursively initialized, I get different outputs from g++: 3 2 1 0 and from

Recursion in MIPS with arrays

邮差的信 提交于 2020-06-02 05:37:08
问题 I'm a beginner user of MARS for programming in MIPS language. I started to study the recursion and I wrote a little method in java that take in input an array and an index, and make a recursive sum of all its elements. But I don't know how to write it in mips language, someone can help me? public int recursiveSum(int i, int[] array) { if(i == array.length-1) return array[i]; return array[i]+recursiveSum(i+1, array); } 回答1: When you create a recursive function in mips , you need to save the

Recursion in MIPS with arrays

♀尐吖头ヾ 提交于 2020-06-02 05:36:50
问题 I'm a beginner user of MARS for programming in MIPS language. I started to study the recursion and I wrote a little method in java that take in input an array and an index, and make a recursive sum of all its elements. But I don't know how to write it in mips language, someone can help me? public int recursiveSum(int i, int[] array) { if(i == array.length-1) return array[i]; return array[i]+recursiveSum(i+1, array); } 回答1: When you create a recursive function in mips , you need to save the

Recursion in MIPS with arrays

左心房为你撑大大i 提交于 2020-06-02 05:36:10
问题 I'm a beginner user of MARS for programming in MIPS language. I started to study the recursion and I wrote a little method in java that take in input an array and an index, and make a recursive sum of all its elements. But I don't know how to write it in mips language, someone can help me? public int recursiveSum(int i, int[] array) { if(i == array.length-1) return array[i]; return array[i]+recursiveSum(i+1, array); } 回答1: When you create a recursive function in mips , you need to save the

How to convert this function from recursive to iterative?

末鹿安然 提交于 2020-06-01 05:50:29
问题 I have this method: static List<string> permutation(List<string> lst) { switch (lst.Count) { case 0: case 1: return lst; default: List<string> l = new List<string>(); for (int i = 0; i < lst.Count; i++) { string m = lst[i]; List<string> remLst = lst.Except(new List<string> { m }).ToList(); List<string> tmp = permutation(remLst); for (int i2 = 0; i2 < tmp.Count; i2++) { l.Add(m + tmp[i2]); } } return l; } } which gives all permutations of the list lst . The idea is to one by one extract all

permutations in Javascript

℡╲_俬逩灬. 提交于 2020-05-30 08:13:56
问题 I'm trying to write a function in Javascript that can return the number of permutations, and also show all the permutations of a string (suppose that non of the character is repeated) using recursive methods. I've seen a lot using for loop, but is there a way that I can obtain the same outcome without using it? For the number of permutations, here is my attempt without using for loop var permutation = function (s) { var fac = function (t) { if (t === 0) return 1; return t*fac(t-1); }; return

permutations in Javascript

拜拜、爱过 提交于 2020-05-30 08:13:46
问题 I'm trying to write a function in Javascript that can return the number of permutations, and also show all the permutations of a string (suppose that non of the character is repeated) using recursive methods. I've seen a lot using for loop, but is there a way that I can obtain the same outcome without using it? For the number of permutations, here is my attempt without using for loop var permutation = function (s) { var fac = function (t) { if (t === 0) return 1; return t*fac(t-1); }; return