업데이트는 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. 원래 질문에서 나는 오류없이 컴파일 할 수 있었지만 문제가 남아 있습니다.
아래 코드에서 매트릭스 결과의 출력을 볼 수 없습니다.
(코드가 원본과 약간 변경되었습니다. "인라인"문에 "정적"을 추가하기 위해 # 두 개의 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