language-extension

What does a && operator do when there is no left side in C?

与世无争的帅哥 提交于 2020-11-25 19:51:59
问题 I saw a program in C that had code like the following: static void *arr[1] = {&& varOne,&& varTwo,&& varThree}; varOne: printf("One") ; varTwo: printf("Two") ; varThree: printf("Three") ; I am confused about what the && does because there is nothing to the left of it. Does it evaluate as null by default? Or is this a special case? Edit: Added some more information to make the question/code more clear for my question. Thank you all for the help. This was a case of the gcc specific extension.

What does a && operator do when there is no left side in C?

荒凉一梦 提交于 2020-11-25 19:50:09
问题 I saw a program in C that had code like the following: static void *arr[1] = {&& varOne,&& varTwo,&& varThree}; varOne: printf("One") ; varTwo: printf("Two") ; varThree: printf("Three") ; I am confused about what the && does because there is nothing to the left of it. Does it evaluate as null by default? Or is this a special case? Edit: Added some more information to make the question/code more clear for my question. Thank you all for the help. This was a case of the gcc specific extension.

Using Overloaded Strings

痴心易碎 提交于 2020-01-01 04:45:09
问题 OverloadedStrings extension is really very useful, however it has some downsides. Consider the following function definition: someFunction :: ToJSSTring a => a -> IO () someFunction = js_function . toJSSTring In this case when if I want to pass a literal value I have to add a type signature explicitly when OverloadedStrings is enabled: someFunction ("This is plain string" :: String) someFunction ("And this one is Text" :: Data.Text.Text) The reason for this necessity is quite obvious, I

Breaking Data.Set integrity without GeneralizedNewtypeDeriving

爱⌒轻易说出口 提交于 2019-12-29 06:37:07
问题 The code below uses an unsafe GeneralizedNewtypeDeriving extension to break Data.Set by inserting different elements with different Ord instances: {-# LANGUAGE GeneralizedNewtypeDeriving #-} import Data.Set import System.Random class AlaInt i where fromIntSet :: Set Integer -> Set i toIntSet :: Set i -> Set Integer instance AlaInt Integer where fromIntSet = id toIntSet = id newtype I = I Integer deriving (Eq, Show, AlaInt) instance Ord I where compare (I n1) (I n2) = compare n2 n1 -- sic!

How would I extend the JavaScript language to support a new operator?

不羁岁月 提交于 2019-12-17 17:32:11
问题 The answer to the question Is it possible to create custom operators in JavaScript? is not yet , but @Benjamin suggested that it would be possible to add a new operator using third party tools : It is possible to use third party tools like sweet.js to add custom operators though that'd require an extra compilation step. I will take the same example, like in the previous question: (ℝ, ∘), x ∘ y = x + 2y For any two real numbers x and y : x ∘ y is x + 2y that is also a real number. How can I

make cppcheck skip the PACKAGE definition

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:58:03
问题 I'm using the GUI version of cppcheck 1.64 for static code analysis on C++-Builde-6 code. For DLL exports and imports, the definition of PACKAGE is necessary: /// A dialog exported from a BPL (a VCL-specific kind of DLL) class PACKAGE MySharedDialog { public: // lots of methods to-be checked private: // lots of methods to-be checked // lots of members }; Cppcheck stops when it encounters PACKAGE because it doesn't know what it means: The code 'class PACKAGE TAppInfoDialog {' is not handled.

Can using UndecidableInstances pragma locally have global consequences on compilation termination?

纵饮孤独 提交于 2019-12-08 14:27:59
问题 Suppose a Haskell library designer decides to use UndecidableInstances for some reason. The library compiles fine. Now suppose some program uses the library (like defines some instances of its type classes), but doesn't use the extension. Can it happen that the compilation fails (doesn't terminate)? If such a scenario can happen, I'd be happy to see an example. For example, as mtl uses UndecidableInstances a lot, is it possible to write a program that depends on mtl (or any other standard

MSVC direct constructor call extension

喜你入骨 提交于 2019-12-04 22:09:25
问题 In this response, tloveless pointed out that it's possible in MSVC to use this->foo::foo(42); for constructor delegation to directly call a constructor: #include <iostream> struct foo { int m; foo(int p) : m(p) { std::cout << "foo("<<p<<")\n"; } foo() : m(0) { this->foo::foo(42); std::cout << "foo(), " << m << "\n"; } }; int main() { foo f; std::cin.ignore(); } I was surprised that this even compiles in MSVC; clang++, g++ and me agree it's illegal, e.g. [class.ctor]/2 "Because constructors do

Using Overloaded Strings

我们两清 提交于 2019-12-04 01:47:12
OverloadedStrings extension is really very useful, however it has some downsides. Consider the following function definition: someFunction :: ToJSSTring a => a -> IO () someFunction = js_function . toJSSTring In this case when if I want to pass a literal value I have to add a type signature explicitly when OverloadedStrings is enabled: someFunction ("This is plain string" :: String) someFunction ("And this one is Text" :: Data.Text.Text) The reason for this necessity is quite obvious, I suppose OverloadedStrings was designed to ease the passing of literal values to functions that have strict