更新1为什么没有可见的输出?
好消息是,现在我看到的输出通过修正调用mat()
如下。
但是,有一个问题“问题”。
的 “问题” 是如下
Implicit declaration of function 'mat' is invalid in C99
//
// main.m
// MultRosetta
//
// Created by Brian Schott on 12/30/12.
// Copyright (c) 2012 Brian Schott. All rights reserved.
//
#import <Cocoa/Cocoa.h>
// #include "code.m"
/*
int main(int argc, char *argv[])
{
int mat();
return NSApplicationMain(argc, (const char **)argv);
}
*/
int main(int argc, const char * argv[])
{
return((int) mat());
}
更新1
更新0
我的目录列表如下所示。如何从终端(控制台)运行应用程序? 我甚至不认可要运行的可执行文件。
server:MultRosetta brian$ ls -al
total 32
-rw-r--r-- 1 brian staff 449 Dec 30 19:31 inline
-rw-r--r-- 1 brian staff 1441 Dec 30 08:52 code.m
drwxr-xr-x 5 brian staff 170 Dec 30 15:40 MultRosetta.xcodeproj
drwxr-xr-x 9 brian staff 306 Dec 30 16:11 MultRosetta
[email protected] 1 brian staff 6148 Dec 31 08:26 .DS_Store
drwxr-xr-x 13 brian staff 442 Dec 30 08:43 ..
drwxr-xr-x 7 brian staff 238 Dec 31 08:26 .
server:MultRosetta brian$ ls -al MultRosetta.xcodeproj/
total 24
drwxr-xr-x 5 brian staff 170 Dec 30 15:40 .
drwxr-xr-x 7 brian staff 238 Dec 31 08:26 ..
-rw-r--r-- 1 brian staff 12197 Dec 30 15:40 project.pbxproj
drwxr-xr-x 4 brian staff 136 Dec 30 08:43 project.xcworkspace
drwxr-xr-x 3 brian staff 102 Dec 30 08:43 xcuserdata
server:MultRosetta brian$ ls -al MultRosetta
total 48
drwxr-xr-x 9 brian staff 306 Dec 30 16:11 .
drwxr-xr-x 7 brian staff 238 Dec 31 08:26 ..
[email protected] 1 brian staff 283 Dec 30 08:43 BSAppDelegate.h
[email protected] 1 brian staff 380 Dec 30 08:43 BSAppDelegate.m
-rw-r--r-- 1 brian staff 1098 Dec 30 08:43 MultRosetta-Info.plist
[email protected] 1 brian staff 153 Dec 30 08:43 MultRosetta-Prefix.pch
[email protected] 1 brian staff 1531 Dec 30 16:11 code.m
drwxr-xr-x 5 brian staff 170 Dec 30 08:43 en.lproj
[email protected] 1 brian staff 289 Dec 30 10:39 main.m
server:MultRosetta brian$
更新0
This is a followup question。在最初的问题中,我终于可以毫无错误地进行编译,但问题仍然存在。
我在下面的代码中看不到矩阵结果的任何输出。建议我在“inline”语句中添加“static”,I#导入两个Xcode事物,并将主函数名称从“main()”更改为“从main.m
“垫()”和所谓的“垫()”。)
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#include <stdio.h>
#include <stdlib.h>
/* Make the data structure self-contained. Element at row i and col j
is x[i * w + j]. More often than not, though, you might want
to represent a matrix some other way */
typedef struct { int h, w; double *x;} matrix_t, *matrix;
static inline double dot(double *a, double *b, int len, int step)
{
double r = 0;
while (len--) {
r += *a++ * *b;
b += step;
}
return r;
}
matrix mat_new(int h, int w)
{
matrix r = malloc(sizeof(matrix) + sizeof(double) * w * h);
r->h = h, r->w = w;
r->x = (double*)(r + 1);
return r;
}
matrix mat_mul(matrix a, matrix b)
{
matrix r;
double *p, *pa;
int i, j;
if (a->w != b->h) return 0;
r = mat_new(a->h, b->w);
p = r->x;
for (pa = a->x, i = 0; i < a->h; i++, pa += a->w)
for (j = 0; j < b->w; j++)
*p++ = dot(pa, b->x + j, a->w, b->w);
return r;
}
void mat_show(matrix a)
{
int i, j;
double *p = a->x;
for (i = 0; i < a->h; i++, putchar('\n'))
for (j = 0; j < a->w; j++)
printf("\t%7.3f", *p++);
putchar('\n');
}
int mat()
{
double da[] = { 1, 1, 1, 1,
2, 4, 8, 16,
3, 9, 27, 81,
4,16, 64, 256 };
double db[] = { 4.0, -3.0, 4.0/3,
-13.0/3, 19.0/4, -7.0/3,
3.0/2, -2.0, 7.0/6,
-1.0/6, 1.0/4, -1.0/6};
matrix_t a = { 4, 4, da }, b = { 4, 3, db };
matrix c = mat_mul(&a, &b);
/* mat_show(&a), mat_show(&b); */
mat_show(c);
/* free(c) */
// NSLog (@"Here is some amazing text! %@",c);
return 0;
}
是什么让你觉得这没什么用?编译并运行这段代码会产生4行文本。 –
哪里?我没有看到任何。它在自己的应用程序中生成一个窗口。我在控制台中看不到任何输出。它在哪里? – zerowords
你说,“我输入了两个Xcode的东西”,但是你没有输入任何与Xcode相关的东西。你的意思是你进口可可的东西吗?你应该澄清。 Xcode只是一个开发环境,而不是语言或编译器。 Cocoa是Objective-C语言的框架,通常由gcc或clang编译。你在说什么? – user1118321