我有这段看似无辜的代码:
void generate_heightmap(float **terrain) {
}
int main(int argc, char **argv) {
float terrain[1500][1500];
generate_heightmap(terrain);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试编译它时,我得到了这些奇怪的错误,这可能是什么原因?
test.c||In function ‘main’:|
test.c|8|warning: passing argument 1 of ‘generate_heightmap’ from incompatible pointer type [enabled by default]|
test.c|1|note: expected ‘float **’ but argument is of type ‘float (*)[1500]’|
||=== Build finished: 1 errors, 1 warnings ===|
Run Code Online (Sandbox Code Playgroud)
我有GCC 4.6.1和Ubuntu 11.11 64位.
最后一行是什么意思?
a=0;
b=0;
c=0;
a && b++;
c || b--;
Run Code Online (Sandbox Code Playgroud)
你可以用更有趣的例子来解释这个问题吗?
此代码正确,但文件夹大小错误。如果我更改目录,大小总是错误的。例如,“%@/Caches/com.apple.Safari/Webpage Previews”的大小是 23 MB,但我有 16.5 KB。
NSString *path = [NSString stringWithFormat:@"%@/Caches/com.apple.Safari/Webpage Previews", [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
NSNumber *fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] objectForKey:NSFileSize];
resultsize += [fileSize unsignedLongLongValue];
Run Code Online (Sandbox Code Playgroud)
我也用过这个,但大小总是错误的:
NSFileManager *fm = [[NSFileManager alloc] init];
NSURL *LibraryURL = [[fm URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *previewsURL = [LibraryURL URLByAppendingPathComponent:@"Caches/com.apple.Safari/Webpage Previews"];
resultSize += [[[fm attributesOfItemAtPath:[previewsURL path] error:nil] objectForKey:NSFileSize] unsignedIntegerValue];
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗?谢谢。
我正在制作一个8x8 LED矩阵的驱动程序,我是从计算机的并行端口驱动的.这是一个时钟,灵感来自我在Tokyoflash上看到的设计.
驱动程序的一部分是一个3*5数字"精灵"的数组,它们被绘制到矩阵中.矩阵的坐标被分配给精灵的坐标,依此类推,直到在其上绘制整个精灵.对具有偏移的另一个数字重复该过程.我已经验证我已经正确绘制了精灵,并且在写入时矩阵是空白的.但是,当我在矩阵上绘制一个数字时,我在Numpad6上得到左边数字的错误1s,右边是Numpad1(没有绘制左边数字的示例.)
我有一周的C经验,这让我感到困惑.
如果你想自己编译它,这里是完整的驱动程序.它远没有完成.
//8x8 LED MATRIX DRIVER VER 0.1 APR062009
//CLOCK
//
// 01234567
// 0 BXXXXXXH B: Binary Mode Indicator
// 1 DXXXXXXM D: Decimal Mode Indicator
// 2 NNNNNNNN H: Hour Centric Display
// 3 LLLNNRRR M: Minute Centric Display
// 4 LNLNNRNR X: Secondary Information
// 5 LLLNNRRR L: Left Digit
// 6 LNLNNRNR R: Right digit
// 7 LLLNNRRR N: Not Used
#include <stdio.h>
#include <unistd.h>
//#include <math.h>
#include <time.h>
#include </usr/include/sys/io.h> …Run Code Online (Sandbox Code Playgroud) 假设我有两个归类Base和Derived,即:
#include <iostream>
class Base {
public:
Base ()
: m_name("Base")
{
}
virtual ~Base ()
{
}
virtual void method (std::ostream & out) const
{
out << m_name << std::endl;
}
protected:
Base (std::string name)
: m_name(name)
{
}
private:
std::string m_name;
};
class Derived : public Base {
public:
Derived ()
: Base("Derived")
{
}
virtual ~Derived ()
{
}
virtual void method (std::ostream & out) const
{
static_cast<const Base * const>(this)->method(out);
}
}; …Run Code Online (Sandbox Code Playgroud) 这不是家庭作业,只是我的C++课程的一些训练练习,以便习惯于继承和东西.所以练习的第一部分要求我们创建一个程序,它有一个类名Rectangle,我们应该做构造函数getter和setter,找到区域和周长.这部分工作正常.练习的第二部分说要创建一个新的类名Square,它扩展Rectangle,它有一个构造函数,它将作为参数的正方形宽度.然后程序应该打印区域和周边.
#include <iostream>
using namespace std;
class Rectangular {
private:
int width;
int height;
public:
Rectangular () {
width = 5;
height = 5;
}
Rectangular (int w, int h) {
width = w;
height = h;
}
void setWidth (int w) {
width = w;
}
void setHeight (int h) {
height = h;
}
int getWidth () {
return width;
}
int getHeight () {
return height;
}
int getArea () {
return width*height;
}
int getPerimeter () …Run Code Online (Sandbox Code Playgroud) c ×3
c++ ×2
arrays ×1
casting ×1
constructor ×1
inheritance ×1
macos ×1
memory ×1
objective-c ×1
osx-lion ×1
size ×1
types ×1