0

update 1

The good news is that now I see output by correcting the call to mat() as below.

However, there is a problem "issue".

The "issue" is as follows

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() );
}

update 1

update 0

My directory listings are as below. How do I run the app from the Terminal (Console)? I don't even recognize an executable to run.

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
-rw-r--r--@  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 ..
-rw-r--r--@ 1 brian  staff   283 Dec 30 08:43 BSAppDelegate.h
-rw-r--r--@ 1 brian  staff   380 Dec 30 08:43 BSAppDelegate.m
-rw-r--r--  1 brian  staff  1098 Dec 30 08:43 MultRosetta-Info.plist
-rw-r--r--@ 1 brian  staff   153 Dec 30 08:43 MultRosetta-Prefix.pch
-rw-r--r--@ 1 brian  staff  1531 Dec 30 16:11 code.m
drwxr-xr-x  5 brian  staff   170 Dec 30 08:43 en.lproj
-rw-r--r--@ 1 brian  staff   289 Dec 30 10:39 main.m
server:MultRosetta brian$ 

update 0

This is a followup question . In the original question I finally was able to compile without errors, but a problem remains.

I cannot see any output from the matrix result in the code below.

(The code has been changed only slightly from its original. As recommended I added "static" to the "inline" statement, I #imported two Xcode things, and I changed the primary function name from "main()" to "mat()" and called "mat()" from 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;
}
Community
  • 1
  • 1
zerowords
  • 2,915
  • 4
  • 29
  • 44
  • What makes you think this shows nothing? Compiling and running this code emits 4 lines of text. – Lily Ballard Dec 31 '12 at 00:43
  • Where? I don't see any. It produces a window in its own app. I don't see any output in the Console. Where is it? – zerowords Dec 31 '12 at 01:34
  • You say, "I #imported two Xcode things", but you didn't import anything related to Xcode. Do you mean that you imported Cocoa things? You should clarify. Xcode is just a development environment, not a language or a compiler. Cocoa is the framework for the Objective-C language and is compiled by gcc or clang, usually. Which are you talking about? – user1118321 Dec 31 '12 at 03:29
  • Sorry, I guess the term is Cocoa things. Where is the output, though? – zerowords Dec 31 '12 at 04:25

1 Answers1

1

You should be able to see this output if you open up the Xcode console (which you can do, while in Xcode 4, (Shift + Command + C to activate the console and Shift + Command + Y to toggle viewing & hiding the debug area).

Or, you can run the executable (your compiled binary app) from the command line and you can see the output there.

EDITED:

Here's a screenshot of my Xcode window, where you can see I made a test project and dropped your code in (assuming you set it up as a "Foundation" command line tool).

Two Ways to see output

Method # 1 is demonstrated in the "Output" section of the Xcode window.

Method # 2 would be to "show in Finder" the compiled product, and then drag & drop that app into a Terminal window and you can launch it by just hitting Return after the path gets displayed.

Another thought I just realized... it may be that your code isn't running at all. For me to run your code, I had to add this function to my .m file:

int main(int argc, const char * argv[])
{
    return( mat() );
}

Do you actually invoke the "mat()" function when you're testing?

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • I cannot see anything in the Xcode console. Please look at my edited question to see my directory listing and tell me how to run my executable. I don't see an executable and I don't really know how to run one except to type an executables name into the Terminal. Please give more info. – zerowords Dec 31 '12 at 13:42
  • Bingo! I had to add your code to MY .m file. I have shown the revised .m file as an update to the question. Now I am only getting a minor "issue" message which I would like help in cleaning up, if you don't mind. See the **update 1** in the original question. But the main problem is fixed because I am seeing the output. Another minor problem is in the Xcode navigator, my Products is not like yours. Mine is just a graphic show papers, pencil, ruler, and a brush. – zerowords Dec 31 '12 at 15:05
  • 1
    From the compiler warning "`Implicit declaration of function 'mat' is invalid in C99`", it sounds like all you do is need a function declaration at the top of your .m file (or better, in a .h file). The function delcaration looks like this: "`int mat()`" – Michael Dautermann Dec 31 '12 at 17:23