literals

format not a string literal and no format arguments [-Wformat-security]

核能气质少年 提交于 2019-12-12 14:32:37
问题 I am not sure what is causing this error ./lhapdf_wrap.cc: In function ‘void SWIG_Python_AddErrorMsg(const char*)’: ./lhapdf_wrap.cc:877:62: warning: too many arguments for format [-Wformat-extra-args] PyErr_Format(type, "%s", PyString_AsString(old_str), mesg); ^ ./lhapdf_wrap.cc:881:42: warning: format not a string literal and no format arguments [-Wformat-security] PyErr_Format(PyExc_RuntimeError, mesg); ^ The code is: SWIGRUNTIME void SWIG_Python_AddErrorMsg(const char* mesg) { PyObject

Python Convert String Literal to Float

元气小坏坏 提交于 2019-12-12 11:35:22
问题 I am working through the book "Introduction to Computation and Programming Using Python" by Dr. Guttag. I am working on the finger exercises for Chapter 3. I am stuck. It is section 3.2, page 25. The exercise is: Let s be a string that contains a sequence of decimal numbers separated by commas, e.g., s = '1.23,2.4,3.123' . Write a program that prints the sume of the numbers in s. The previous example was: total = 0 for c in '123456789': total += int(c) print total. I've tried and tried but

How to detect the passing of a string literal to a function in C?

别等时光非礼了梦想. 提交于 2019-12-12 11:03:08
问题 I am trying to implement an eqivilent version of perl's chomp() function in C and I have come across a corner case where a string literal passed as the argument will cause a segmentation fault (rightfully so). Example chomp("some literal string\n"); Is there a defined way in C99 to detect wether or not my function was passed a string literal so that I can return without attempting to NUL it out? char* chomp(char *s) { char *temp = s; if (s && *s) { s += strlen(s) - 1; if (*s == '\n') { *s = '

A way of writing large numeral literals in C#

杀马特。学长 韩版系。学妹 提交于 2019-12-12 10:51:44
问题 I have a method like this: Prefix GetPrefix(decimal value) { if(value > 11000000000000000000) return Prefix.CosmicBig; if(value > 1000000000000000) return Prefix.ReallyBig; if(value > 3000000000000) return Prefix.Big; if(value > 50000000) return Prefix.Okay; if(value > 750000) return Prefix.MostlyNormal; if(value > 750000) return Prefix.SoSo; if(value > 750) return Prefix.Small; return Prefix.MiserablySmall; } The exact values are not important. What matters is that they are sometimes changed

Why can't string literals be used in bash regular expression tests?

限于喜欢 提交于 2019-12-12 10:39:45
问题 Why does the following bash script only print out variable worked ? #! /bin/bash foo=baaz regex='ba{2}z' if [[ $foo =~ 'ba{2}z' ]]; then echo "literal worked" fi if [[ $foo =~ $regex ]]; then echo "variable worked" fi Is there something in the bash documentation that states the =~ operator only works with variables, not literals? Does this limitation apply to any other operators? 回答1: You don't need quotes for bash regex anymore: #! /bin/bash foo=baaz regex='ba{2}z' if [[ $foo =~ ba{2}z ]];

Scala hex literal for bytes

百般思念 提交于 2019-12-12 09:54:07
问题 Hex literal containing A-F digit are converting to int by default. When I am trying to declear an Int with 0x it is creating correctly. val a: Int = 0x34 val b: Int = 0xFF But when I am trying to declear a Byte with 0x second line is not compiling val a: Byte = 0x34 val b: Byte = 0xFF // compilation error I have found a workaround that is val a: Byte = 0x34 val b: Byte = 0xFF.toByte But is there any decent way to declear a Byte from its hex literal? For example I am trying to declear a Byte

Why does '20000 is 20000' result in True? [duplicate]

此生再无相见时 提交于 2019-12-12 01:29:38
问题 This question already has an answer here : What's with the integer cache maintained by the interpreter? (1 answer) Closed 3 years ago . is in Python tests if 2 references point to the same object. Numbers between -5 and 256 are cached internally so: a = 10 b = 10 a is b # Results in True How does this explain something like: 20000 is 20000 # Results in True Both numbers are above 256. Should not the 2 integers be 2 distinct objects? 回答1: The Python interpreter sees you are re-using a

Printing a literal python string in octal

 ̄綄美尐妖づ 提交于 2019-12-11 15:11:16
问题 For reasons unknown I am the consumer of metadata that needs to be displayed in octal format to be used. I am trying to figure out how to represent it as an octal. Example: x = "\n)\n\022foobar" print x ) foobar print repr(x) '\n)\n\x12foobar' how do i get x to print the way it was assigned, which is in octal encoding? 回答1: You can't; that representation is lost. If you want to output "\022" then you need to either process it yourself or you need to store "\\022" instead. 来源: https:/

Byte string spanning more than one line

心不动则不痛 提交于 2019-12-11 11:32:55
问题 I need to parse byte string which spans more than one line in the source code. Like this self.file.write(b'#compdef %s\n\n' '_arguments -s -A "-*" \\\n' % (self.cmdName,)) this line throws the following exception builtins.SyntaxError: cannot mix bytes and nonbytes literals which can be fixed in the following way self.file.write(b'#compdef %s\n\n\'\'_arguments -s -A "-*" \\\n' % (self.cmdName,)) Notice the backslashes after \n . but this fix does the follow the project rules of less than 79

Literal Strings [Lua 5.1]

泄露秘密 提交于 2019-12-11 10:24:38
问题 So I started to learn Lua(5.1) and I saw that thing called literal strings. And I have no idea what these do. The manual says \a is a bell but when I type print('hello\athere') The IDE prints a weird square with 'bel' written on it. So if someone could help me and explain every one of them[Literal Strings]. that would be really helpful. p.s. i use Sublime Text 3 回答1: Only ASCII between 0x20 and 0x7E are printable characters. How other characters are output, including '\a' and '\b' , is up to