多长时间需要用C来声明一个变量,例如int x或unsigned long long var?我想知道它是否会使我的代码更快地在这样的东西.
for (conditions) {
int var = 0;
// code
}
Run Code Online (Sandbox Code Playgroud)
这样做会更快,还是更容易?
int var;
for (conditions) {
var = 0;
// code
}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
假设foo是C++程序中的摘要 class,为什么声明类型的变量foo*而不是类型的变量是可接受的foo?
我需要在我的XML文档的顶部使用XML编码和版本XDocument.
我有这个,但它是小写的,它需要是大写的.
我需要做什么?
我使用XDocument名为'doc' 的类声明了一个新的XML文档.
我使用保存到文件doc.Save();.
我试过了:
doc.Declaration.Encoding.ToUpper();XDeclarationdoc.Declaration为my XDeclaration.它仍以小写形式出现.
使用未命名的命名空间和全局声明有什么区别?
使用这两个是否有任何特定的背景?
我们可以在外部源文件中访问未命名的命名空间组件吗?
如果我声明一个空图像:
var myImage: UIImage?
Run Code Online (Sandbox Code Playgroud)
然后给它一个值:
myImage = UIImage(named: "drawing.png")
Run Code Online (Sandbox Code Playgroud)
我怎样才能在以后删除该值,将其恢复到原来的空状态?
我尝试了以下内容
struct mbuf
{
cacheline: *mut [u64], // great amount of rows follows below
// ..........
}
static mut arr: [mbuf; 32]; // Q1 my main aim
// something as before but using Vec; // Q2 also main aim
fn main() {
// let static mut arr: [mbuf; 32]; // Q3 also doesn't work
// static mut arr: [mbuf; 32]; // Q3 also doesn't work
}
Run Code Online (Sandbox Code Playgroud)
并得到错误
src/main.rs:74:29: 74:30 error: expected one of `+` or `=`, found `;`
src/main.rs:74 static …Run Code Online (Sandbox Code Playgroud) 我正在玩这种语言来开始学习,我对于递归定义的工作方式感到困惑.
例如,让我们采用三角数的序列(TN n = sum [1..n])
提供的解决方案是:
triangularNumbers = scanl1 (+) [1..]
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.
但我提出的解决方案是:
triangularNumbers = zipWith (+) [1..] $ 0 : triangularNumbers
Run Code Online (Sandbox Code Playgroud)
这也是正确的.
现在我的问题是:这如何转化为较低级别的实现?当满足这样的递归定义时,场景背后会发生什么?
在C语言中,如果我们写这个:
for(int i = 0; i < 7; i++)
{
// for loop Body
}
Run Code Online (Sandbox Code Playgroud)
变量的范围i在for循环体内.没关系.
但是,如果我这样写:
for(int i = 0; i < 7; i++)
{
long int i = 1; // Redeclaration of i
}
Run Code Online (Sandbox Code Playgroud)
这里,变量i在循环体内再次声明,但它成功编译并在C中运行.
但是,在C++中,编译器会"重新声明'long int i'"错误.
那么,为什么C编译器没有给出重新声明错误?这是编译器错误吗?
我在头文件中有以下函数声明:
extern void flash(const char *message, const enum msg_type type);
Run Code Online (Sandbox Code Playgroud)
基本上,它采用两个参数并将相应的消息推送到全局消息队列中。由于不需要修改参数,因此我对它们进行了const限定。但是,CLion的静态代码分析器对此发出了警告:
Clang-Tidy:参数'type'在函数声明中是const限定的;参数的const限定仅对函数定义有影响
这是我的问题:
const限定词也没有效果。我正在使用以下标志(其中cc是gcc 4.2或clang 8.0):
$ cc -Wall -Werror -pedantic -ansi -std=c89 main.c
(我知道-ansi标志在这种情况下有点多余)
以下给了我预期的错误
main.c:31:8: warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
vec3 abc = {0};
Run Code Online (Sandbox Code Playgroud)
int main()
{
vec3 a = {0};
vec3 b = {0};
Vec3(2, 2, 2);
vec3 abc = {0}; // Declared after a function call
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,以下内容不
int main()
{
vec3 a = Vec3(0, 1, 2);
vec3 b = Vec3(0, 1, 2);
vec3 abc = {0}; // Declared after a function call …Run Code Online (Sandbox Code Playgroud) declaration ×10
c ×4
c++ ×3
variables ×3
.net ×1
c# ×1
c89 ×1
clang-tidy ×1
clion ×1
const ×1
corecursion ×1
for-loop ×1
global ×1
globals ×1
haskell ×1
linq-to-xml ×1
namespaces ×1
optimization ×1
recursion ×1
rust ×1
statements ×1
static ×1
swift ×1
types ×1
xml ×1