Fell in Love with 'C'

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 738 Views - Last Post: 01 September 2012 - 01:58 PM Rate Topic: -----

#1 Miikalsen  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 29-December 11

Fell in Love with 'C'

Posted 01 September 2012 - 07:51 AM

Well.. So basiclly i have been switching bewteen languages the past year. All from python to c++. My favor being c++. But I started with java for real learning kinda much. But i hate the syntax within java because It's horrifying long.

So today i took the time too look at 'c' and i kinda liked it a lot. It's almost the same as C++ just easier. Which i believe is perfect. Later on i would move on to either C++ or C#. Becuase off I want to continue with game creation.

But I'm currently watching a series on youtube for 'C' which i think everyone should watch. As it has been though to find a nice series. So thought i would share it. And ask what you think about my interest in continue after C and soforth.


What I'm learning from is: http://www.youtube.c...170B6E7DD6D8810

Currently on video 18.


EDIT: Little thing i just made:

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int nums[] = { 1,2,3,4,5 };
   int reversed[5];

   int i;
   for (i = 0; i < 5; i++)
   {
       reversed[4 - i] = nums[i];
   }

   for (i = 0; i <5; i++)
   {
       printf ("%i", reversed[i]);
   }
    return 0;
}

This post has been edited by Miikalsen: 01 September 2012 - 08:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Fell in Love with 'C'

#2 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Fell in Love with 'C'

Posted 01 September 2012 - 08:12 AM

Actually, once you dig in a little deeper, you will find C++ has all the features of C and more. Earlier, I used to hate C++. But after using it for a while, I think C is a subset of C. But in the end, it's upto you. And about the game making, you can even make games in C, so using C++/# is not necessary. As I said, it's upto you :)
Was This Post Helpful? 0
  • +
  • -

#3 Miikalsen  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 29-December 11

Re: Fell in Love with 'C'

Posted 01 September 2012 - 08:51 AM

Didn't knew you could make games in C. What libraries are being used for that?


Also. You say that C is a subset of C++ Which i find to be very positive. But the fact that C++ in some weird way is harder then 'C'. Make's me thinking that I'll have a real hard time learning CPP.
Was This Post Helpful? 0
  • +
  • -

#4 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Fell in Love with 'C'

Posted 01 September 2012 - 08:55 AM

Well, any library like DirectX or Allegro or OpenGL can be used. I recommend against DirectX until you get some (read a lot) of experience in C. And some features in C++ are a little difficult, but mostly it is easy. If you learn C properly, you can learn C++ very easily.
Was This Post Helpful? 0
  • +
  • -

#5 Miikalsen  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 29-December 11

Re: Fell in Love with 'C'

Posted 01 September 2012 - 08:56 AM

Thanks a lot for that informative posts.

I'm looking to continue with C++ once my 'C' skills are much higher. I need as well to understand the language so i can figure how to create things if you know what i mean.
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is online

  • member icon


Reputation: 3987
  • View blog
  • Posts: 12,298
  • Joined: 25-December 09

Re: Fell in Love with 'C'

Posted 01 September 2012 - 09:06 AM

C and C++ are very different. One is primarily a procedural language the other is primarily an Object Oriented Language. To properly use C++ you need to think differently than you do using C.

In some ways C++ is more difficult. One reason is that C++ strictly enforces types, where C doesn't. Also if you include the Standard Template Language as part of C++ then C++ is a much larger language. However in some aspects, in my opinion, C++ is much simpler. For example I find the C++ streams much simpler than trying to remember the format specifiers of scanf() and printf(). However at the same time sometimes C's printf() is much easier to format text than the C++ streams.

In either case properly learning and using either language has it's difficulties. If you really want to work in an area of the industry that primarily uses one language or the other I recommend you concentrate on learning that language. In my opinion you don't need to learn one language before the other, and sometimes learning C before C++ requires you to unlearn some things to properly use the language, the same is true in reverse.

But you shouldn't think of C as a subset of C++ there are differences now between the two standards, and I expect to see more differences in the future. As well as differences in methods and thinking.

Jim

This post has been edited by jimblumberg: 01 September 2012 - 09:08 AM

Was This Post Helpful? 0
  • +
  • -

#7 Miikalsen  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 29-December 11

Re: Fell in Love with 'C'

Posted 01 September 2012 - 09:16 AM

View Postjimblumberg, on 01 September 2012 - 09:06 AM, said:

C and C++ are very different. One is primarily a procedural language the other is primarily an Object Oriented Language. To properly use C++ you need to think differently than you do using C.

In some ways C++ is more difficult. One reason is that C++ strictly enforces types, where C doesn't. Also if you include the Standard Template Language as part of C++ then C++ is a much larger language. However in some aspects, in my opinion, C++ is much simpler. For example I find the C++ streams much simpler than trying to remember the format specifiers of scanf() and printf(). However at the same time sometimes C's printf() is much easier to format text than the C++ streams.

In either case properly learning and using either language has it's difficulties. If you really want to work in an area of the industry that primarily uses one language or the other I recommend you concentrate on learning that language. In my opinion you don't need to learn one language before the other, and sometimes learning C before C++ requires you to unlearn some things to properly use the language, the same is true in reverse.

But you shouldn't think of C as a subset of C++ there are differences now between the two standards, and I expect to see more differences in the future. As well as differences in methods and thinking.

Jim



I understand what you are saying. I'm not experienced enough to make decision on what's easiest myself yet so far i have had a basic understand of some of the simplest syntax's and differences. Like the printing to screen. It's horrifying in C at first. But i kinda got more into it after a while. I'm referring to printing variables and such was a pain in the beginning because i was not used to it. But you told me in there that C is not a subset of C++ and that It's good for the industries. But i do not believe It's good for the game industries at all. I was told and taught that C is a Subset of C++. Therefore also taught that i should learn C > Then C++. But if what you saying are true It set's a complete different look at it for me. And I'm starting to re consider what i should do.
Was This Post Helpful? 0
  • +
  • -

#8 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Fell in Love with 'C'

Posted 01 September 2012 - 09:20 AM

Actually, after reading Jim's response, I have to somewhat agree with me. Although many of the things are the same, some of the things are completely different. Still, IMO, it doesn't make much difference. I program in both C and C++, and I don't see much of a difference, except for the fact that C++ provides many useful features to me, which C++ doesn't.
Was This Post Helpful? 0
  • +
  • -

#9 Miikalsen  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 29-December 11

Re: Fell in Love with 'C'

Posted 01 September 2012 - 09:24 AM

May i ask for an example of a difference between the two? Showing some code ?
Was This Post Helpful? 0
  • +
  • -

#10 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Fell in Love with 'C'

Posted 01 September 2012 - 09:28 AM

One of the main things in my opinion is the addition of classes and exception handling.

EDIT : See this
http://compsci.nuvvo...and-c-plus-plus

This post has been edited by aresh: 01 September 2012 - 09:30 AM

Was This Post Helpful? 0
  • +
  • -

#11 sungchoiok  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 140
  • Joined: 18-July 10

Re: Fell in Love with 'C'

Posted 01 September 2012 - 09:50 AM

View PostMiikalsen, on 01 September 2012 - 11:24 AM, said:

May i ask for an example of a difference between the two? Showing some code ?


C++

//a pointless program I quickly typed up... might have missed a semicolon somewhere.
class Foo{
  public:
    int a;
    char b;
    int bar();
};

Foo::bar()
{
  return 1;
}

int main()
{
  Foo f;
  std::cout << "hello world" << std::endl;
  int a = f.bar();
  char* b = new char[10];
  delete[] b;
  return 0;
}



You see some stuff that isn't in C, like class, new, delete, etc.

If you start using C++, then go back to C, you would wonder how you have managed to code without them.
Was This Post Helpful? 0
  • +
  • -

#12 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Fell in Love with 'C'

Posted 01 September 2012 - 09:59 AM

sungchoiok, I disagree. Even without C++, I can write this code. Here it is.

//a pointless program somebody else quickly typed up... he might have missed a semicolon somewhere :P/>
typedef struct Foo{
    int a;
    char b;
};

bar(Foo foo) //It does not belong to Foo, but is uses Foo in the same way as a class
{
  return 1;
}

int main()
{
  Foo f;
  printf("hello world\n");
  int a = Foo_bar(f);
  char* b = (int*)calloc(10,sizeof(int));
  free(B)/>;
  return 0;
}


Was it so difficult? :whistling:
Was This Post Helpful? 0
  • +
  • -

#13 sungchoiok  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 140
  • Joined: 18-July 10

Re: Fell in Love with 'C'

Posted 01 September 2012 - 10:07 AM

View Postaresh, on 01 September 2012 - 11:59 AM, said:

sungchoiok, I disagree. Even without C++, I can write this code. Here it is.

//a pointless program somebody else quickly typed up... he might have missed a semicolon somewhere :P/>
typedef struct Foo{
    int a;
    char b;
};

bar(Foo foo) //It does not belong to Foo, but is uses Foo in the same way as a class
{
  return 1;
}

int main()
{
  Foo f;
  printf("hello world\n");
  int a = Foo_bar(f);
  char* b = (int*)calloc(10,sizeof(int));
  free(B)/>;
  return 0;
}


Was it so difficult? :whistling:


Yes, of course, I do realize that everything in C++, one can do in C.
I fear that I should have been more careful with this statement that I made: "If you start using C++, then go back to C, you would wonder how you have managed to code without them."

But then, when it comes to the point of having to write one's own v-tables, I guess one should just write in C++ unless for a very good reason :)

Peace

Was This Post Helpful? 0
  • +
  • -

#14 jimblumberg  Icon User is online

  • member icon


Reputation: 3987
  • View blog
  • Posts: 12,298
  • Joined: 25-December 09

Re: Fell in Love with 'C'

Posted 01 September 2012 - 10:10 AM

From your post this is probably the biggest difference:

Quote

C does not have any classes or objects. It is procedure and function driven. There is no concept of access through objects and structures are the only place where there is a access through a compacted variable. c++ is object oriented.


The differences between procedural programming and OOP is quite stunning. Wait until you really start experimenting and creating template classes, using inheritance and polymorphism, all of which are not available in C. These concepts will require a different approach to use properly.

Also, there are quite a few errors in that post, I wouldn't recommend using it as a proof.

For example:

Quote

C input/output is based on library and the processes are carried out by including functions. C++ i/o is made through console commands cin and cout.

Both C and C++ input/output is based on a library and including functions. The difference is that C++ is using a class, istream for cin/cout, but you still use a function, in this case either the cin or cout istream member functions.

Quote

Undeclared functions in c++ are not allowed. The function has to have a prototype defined before the main() before use in c++ although in c the functions can be declared at the point of use.

With the current standard it doesn't matter what language you use, you must define, or prototype a function before you can use them.

Quote

For an int main() in c++ we may not write a return statement but the return is mandatory in c if we are using int main().

Again this is not the case with the current standards. Both C and C++ will return 0 to the operating system if you fail to include a return statement. And in both C and C++ main must be defined to return an int in a hosted environment. C no longer allows default int return types.

Quote

C does not support new or delete commands. The memory operations to free or allocate memory in c are carried out by malloc() and free().

True C does not support new or delete. However the biggest difference is that new and delete will call C++ class constructors and destructors to properly create and destroy the objects, malloc/free have no concept of objects, everything is a byte.

Jim
Was This Post Helpful? 0
  • +
  • -

#15 jimblumberg  Icon User is online

  • member icon


Reputation: 3987
  • View blog
  • Posts: 12,298
  • Joined: 25-December 09

Re: Fell in Love with 'C'

Posted 01 September 2012 - 10:16 AM

View Postaresh, on 01 September 2012 - 11:59 AM, said:

sungchoiok, I disagree. Even without C++, I can write this code. Here it is.

//a pointless program somebody else quickly typed up... he might have missed a semicolon somewhere :P/>
...
  char* b = (int*)calloc(10,sizeof(int));
  free(B)/>;
  return 0;
}


Was it so difficult? :whistling:

But in a C program you should not be casting the return value of malloc/calloc. And why are you allocating more memory than you need. An int is larger than a char. So your call should actually be:
char* b = calloc(10,sizeof(char));
// Or since the size of a character is well defined:
char* c = calloc(10,1);


Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2