Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Tidbits and Tricks for programming
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Dan




PostPosted: Fri May 07, 2004 12:00 pm   Post subject: (No subject)

U should only uses proces when they are needed, it dose not make scen to uses them rather then a procedure. And the avg new user dose not use them right b/c they do not understand the conspects of multy treading.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri May 28, 2004 4:23 pm   Post subject: (No subject)

when you're typing out your code:
if you've typed this:
code:

for n : 1 .. 100

hit ctrl + enter, it will skip a line and type end for.
it even works if you've just typed
code:

for

it also works for ifs and loops and functions and whatnot.

EDIT: only works with Turing 4.0.5
Andy




PostPosted: Thu Jun 03, 2004 8:32 pm   Post subject: (No subject)

wow.. thats cool... very useful for me cuz when i program in turing, i like to finish my loops/if statements/procs just so the indent will look prettier.. thx
wtd




PostPosted: Mon Sep 27, 2004 2:39 pm   Post subject: (No subject)

dodge_tomahawk wrote:
in turing, you can just pass an array through a function and use upper to how big it is, in c, you have to shove the size in as well, kinda annoying


C++ templates and runtime type inferencing make this much easier.

code:
#include <iostream>

template <typename T, size_t N>
void println_all(T (&arr)[N])
{
        for (int i = 0; i < N; i++)
        {
                std::cout << arr[i] << std::endl;
        }
}

int main()
{
        int a[] = {3,4,5};
        println_all(a);
}
rizzix




PostPosted: Mon Sep 27, 2004 9:15 pm   Post subject: (No subject)

correct me if i'm wrong but i'm not sure that code would work for something like this:

code:

int a[] = new int[3];
a[0] = 1;
a[1] = 2;
a[2] = 3;
println_all(a);


basically a dynamically allocted array?
wtd




PostPosted: Mon Sep 27, 2004 9:31 pm   Post subject: (No subject)

rizzix wrote:
correct me if i'm wrong but i'm not sure that code would work for something like this:

code:

int a[] = new int[3];
a[0] = 1;
a[1] = 2;
a[2] = 3;
println_all(a);


basically a dynamically allocted array?


Apparently not, according to my quick check.
rizzix




PostPosted: Mon Sep 27, 2004 9:33 pm   Post subject: (No subject)

ic intersting.. i got to check this out myself.. nice tip btw!! 8)
wtd




PostPosted: Mon Sep 27, 2004 9:40 pm   Post subject: (No subject)

I think what you're looking for is:

code:
int * a = new int[3];
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Mon Sep 27, 2004 9:40 pm   Post subject: (No subject)

hmm then i get:
code:
test.cpp: In function `int main()':
test.cpp:20: error: no matching function for call to `println_all(int*&)'
wtd




PostPosted: Mon Sep 27, 2004 9:44 pm   Post subject: (No subject)

rizzix wrote:
hmm then i get:
code:
test.cpp: In function `int main()':
test.cpp:20: error: no matching function for call to `println_all(int*&)'


Yes, because as far as the compiler is concered, a is just a pointer, and what's getting passed in is a reference to a pointer, not an array.

I believe it's a case of the compiler just not holding onto enough information to make this work. A and C++ compilers are notoriously lacking in their storage of information. The fact that many other languages do preserve this information is what opens up a lot of opportunities for optimization.
rizzix




PostPosted: Mon Sep 27, 2004 9:45 pm   Post subject: (No subject)

yep thats true.. so i guess it only works for staticly allocated arrays.

EDIT: i'm not sure if this is the expected behaviour of ANSI C++ nywyz.. i had a feeling it would not work for dynamically allocated arrays.. but i dont see why not.. but then again.. instead of a literal (in our case 3) it could have been a variable.. then it appears to make more sense to why not.. of course i'm talking about dynamic'ly allocated arrays only.
wtd




PostPosted: Mon Sep 27, 2004 9:49 pm   Post subject: (No subject)

rizzix wrote:
yep thats true.. so i guess it only works for staticly allocated arrays.


There might be a way to make it work. I just haven't found it yet. Smile
rizzix




PostPosted: Mon Sep 27, 2004 9:52 pm   Post subject: (No subject)

now i have second thoughts, i mean.. ok i need something clarified: does RTTI check allocated sizes etc.. or just Types only.
wtd




PostPosted: Mon Sep 27, 2004 9:59 pm   Post subject: (No subject)

rizzix wrote:
now i have second thoughts, i mean.. ok i need something clarified: does RTTI check allocated sizes etc.. or just Types only.


I'm thinking it just checks types.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 29 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: