下面的程序涉及一个隐式缩小的函数参数.信息可能会丢失.
void func(short) {}
int main()
{
int i = 0x7fffffff;
func(i);
}
Run Code Online (Sandbox Code Playgroud)
如果我使用gcc编译这个程序(无论是C还是C++),-Wall -Wextra我都不会收到任何警告!
当然,这种行为通常被认为是不合需要的.
是否有一些gcc命令行参数会在发生这些缩小的转换时触发诊断消息?
我正在查看一些第三方代码,我不确定一行是做什么的.我无法发布确切的代码,但它是:
bool function(float x)
{
float f = doCalculation(x);
return x > 0 ? f : std::numeric_limits<float>::infinity();
}
Run Code Online (Sandbox Code Playgroud)
这显然会引发编译器关于转换float-> bool的警告,但实际行为是什么?Visual C++如何将浮动转换为bools?至少我应该能够取代那令人讨厌的无限......
我不是C/C++的专家.
我今天发现了这个宣言:
typedef NS_OPTIONS(NSUInteger, PKRevealControllerType)
{
PKRevealControllerTypeNone = 0,
PKRevealControllerTypeLeft = 1 << 0,
PKRevealControllerTypeRight = 1 << 1,
PKRevealControllerTypeBoth = (PKRevealControllerTypeLeft | PKRevealControllerTypeRight)
};
Run Code Online (Sandbox Code Playgroud)
你们能翻译每个价值会有什么价值吗?
我可以使用MinGW编译C代码没问题,但由于某种原因我无法编译C++.我已经尝试过其他编译器,cygnus和cygwin.我正在使用JGrasp.这是错误提要:
----jGRASP wedge2 error: command "g++" not found.
---- This command must be in the current working directory
---- or on the current PATH to use this function.
---- PATH is ";C:\Program Files\Common Files\Microsoft Shared\Windows Live;
C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live
C:\windows\system32;
C:\windows;C:\windows\System32\Wbem;
C:\windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Windows Live\Shared;
C:\mingw\bin;
C:\cygnus\cygwin-b20\H-i586-cygwin32\bin;
C:\cygwin\bin;".
----jGRASP: operation complete.
Run Code Online (Sandbox Code Playgroud) 我有以下IF声明,我无法弄清楚它的含义:
if (data->tokens.size())
{..
//reads each token in a for loop and assigns each token to a variable...
}
Run Code Online (Sandbox Code Playgroud)
令牌中有六个值,所以tokens.size()应该返回6,对吧?
我不明白为什么我们需要if条件呢?据我所知,如果条件将tokens.size()返回1,则返回1,如果返回0则返回false .
在我的情况下,它返回6(或任何数量的令牌,可以是任何数字,而不只是0或1).那么如果条件有效呢?
换句话说,我想知道在获得0和1以外的值时如何处理.
我想知道你可以传递给函数的参数数量是否有限制.
我只是想知道,因为我必须在我的工作中保持5个以上参数的功能.
是否存在关键性阈值nbArguments,谈论性能,还是线性?
请查看以下代码
Main.cpp的
#include <iostream>
using namespace std;
int main()
{
Class1 c;
}
Run Code Online (Sandbox Code Playgroud)
Class1.cpp
#include <iostream>
using namespace std;
class Class1
{
public:
void click1()
{
cout << "Click 1" << endl;
}
};
Run Code Online (Sandbox Code Playgroud)
Class2.cpp
#include <iostream>
using namespace std;
class Class2
{
public:
void click2()
{
cout << "Click 2" << endl;
}
};
Run Code Online (Sandbox Code Playgroud)
如果我将头文件添加到上面的类,它们可以工作.为什么C++在没有头文件的情况下不理解不同文件中的类?
我正在使用带有SDL2的OpenGL 4.4.我试图渲染一个带有顶点(-1,-1,0),(1,-1,0),(0,1,0)的简单三角形.但是,当我认为我正确地做了一切时,没有任何东西被画出来.
我从项目中提取并重新组织了相关代码:
#include <cerrno>
#include <cstring>
#include <exception>
#include <fstream>
#include <iostream>
#include <string>
#include <GL/glew.h>
#include <GL/glu.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
void init();
void cleanUp();
std::string loadShader(std::string filepath);
void checkShaderSuccess(GLuint shader);
SDL_Window* win;
SDL_GLContext glContext;
GLuint program, vertShader, fragShader, vao, vbo;
class GenError: public std::exception {
public:
GenError():
exception(), msg("") {}
GenError(const std::string& m):
exception(), msg(m) {}
virtual ~GenError() throw() {}
virtual const char* what() const throw() {
return msg.c_str();
}
private:
std::string msg;
};
int main() { …Run Code Online (Sandbox Code Playgroud) 所以我一直在尝试获取数组大小及其元素的输入,然后将元素显示到屏幕上,但是当我举例来说数组的大小:7数组的元素:1 2 3 4 5 6 7输出是:
1
2
3
4
5
6
6
Run Code Online (Sandbox Code Playgroud)
代码 :
#include <iostream>
using namespace std;
int main () {
int n , Arr[n];
cout << "please put the size of the array " ;
cin >> n;
cout << "please enter array's elemets ";
for (int k=0; k<n ; k++) {
cin >> Arr[k];
}
for (int i=0;i<n;i++){
cout << Arr[i] << endl;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个简单的操作系统,并且遇到了一些输出闪烁的问题(请参阅此剪辑)。除了内存问题之外,我很不知道是什么原因造成的。
内核.cpp
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
#define FPS 30
#define PIT_HERTZ 1193131.666
#define CLOCK_HIT (int)(PIT_HERTZ/FPS)
const unsigned char font[128-32][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space)
{ 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!)
{ 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (")
{ 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#)
{ 0x0C, 0x3E, 0x03, 0x1E, …Run Code Online (Sandbox Code Playgroud) c++ ×9
c ×3
arguments ×1
arrays ×1
assembly ×1
c++98 ×1
cocoa ×1
cocoa-touch ×1
function ×1
gcc ×1
glsl ×1
header-files ×1
if-statement ×1
ios ×1
jgrasp ×1
mingw ×1
objective-c ×1
opengl-4 ×1
osdev ×1
sdl-2 ×1
visual-c++ ×1
x86 ×1