Announcement

Collapse

Forum Rules and Etiquette

Our mission ...

This forum is part of our mission to promote the preservation of vintage computers through education and outreach. (In real life we also run events and have a museum.) We encourage you to join us, participate, share your knowledge, and enjoy.

This forum has been around in this format for over 15 years. These rules and guidelines help us maintain a healthy and active community, and we moderate the forum to keep things on track. Please familiarize yourself with these rules and guidelines.


Rule 1: Remain civil and respectful

There are several hundred people who actively participate here. People come from all different backgrounds and will have different ways of seeing things. You will not agree with everything you read here. Back-and-forth discussions are fine but do not cross the line into rude or disrespectful behavior.

Conduct yourself as you would at any other place where people come together in person to discuss their hobby. If you wouldn't say something to somebody in person, then you probably should not be writing it here.

This should be obvious but, just in case: profanity, threats, slurs against any group (sexual, racial, gender, etc.) will not be tolerated.


Rule 2: Stay close to the original topic being discussed
  • If you are starting a new thread choose a reasonable sub-forum to start your thread. (If you choose incorrectly don't worry, we can fix that.)
  • If you are responding to a thread, stay on topic - the original poster was trying to achieve something. You can always start a new thread instead of potentially "hijacking" an existing thread.



Rule 3: Contribute something meaningful

To put things in engineering terms, we value a high signal to noise ratio. Coming here should not be a waste of time.
  • This is not a chat room. If you are taking less than 30 seconds to make a post then you are probably doing something wrong. A post should be on topic, clear, and contribute something meaningful to the discussion. If people read your posts and feel that their time as been wasted, they will stop reading your posts. Worse yet, they will stop visiting and we'll lose their experience and contributions.
  • Do not bump threads.
  • Do not "necro-post" unless you are following up to a specific person on a specific thread. And even then, that person may have moved on. Just start a new thread for your related topic.
  • Use the Private Message system for posts that are targeted at a specific person.


Rule 4: "PM Sent!" messages (or, how to use the Private Message system)

This forum has a private message feature that we want people to use for messages that are not of general interest to other members.

In short, if you are going to reply to a thread and that reply is targeted to a specific individual and not of interest to anybody else (either now or in the future) then send a private message instead.

Here are some obvious examples of when you should not reply to a thread and use the PM system instead:
  • "PM Sent!": Do not tell the rest of us that you sent a PM ... the forum software will tell the other person that they have a PM waiting.
  • "How much is shipping to ....": This is a very specific and directed question that is not of interest to anybody else.


Why do we have this policy? Sending a "PM Sent!" type message basically wastes everybody else's time by making them having to scroll past a post in a thread that looks to be updated, when the update is not meaningful. And the person you are sending the PM to will be notified by the forum software that they have a message waiting for them. Look up at the top near the right edge where it says 'Notifications' ... if you have a PM waiting, it will tell you there.

Rule 5: Copyright and other legal issues

We are here to discuss vintage computing, so discussing software, books, and other intellectual property that is on-topic is fine. We don't want people using these forums to discuss or enable copyright violations or other things that are against the law; whether you agree with the law or not is irrelevant. Do not use our resources for something that is legally or morally questionable.

Our discussions here generally fall under "fair use." Telling people how to pirate a software title is an example of something that is not allowable here.


Reporting problematic posts

If you see spam, a wildly off-topic post, or something abusive or illegal please report the thread by clicking on the "Report Post" icon. (It looks like an exclamation point in a triangle and it is available under every post.) This send a notification to all of the moderators, so somebody will see it and deal with it.

If you are unsure you may consider sending a private message to a moderator instead.


New user moderation

New users are directly moderated so that we can weed spammers out early. This means that for your first 10 posts you will have some delay before they are seen. We understand this can be disruptive to the flow of conversation and we try to keep up with our new user moderation duties to avoid undue inconvenience. Please do not make duplicate posts, extra posts to bump your post count, or ask the moderators to expedite this process; 10 moderated posts will go by quickly.

New users also have a smaller personal message inbox limit and are rate limited when sending PMs to other users.


Other suggestions
  • Use Google, books, or other definitive sources. There is a lot of information out there.
  • Don't make people guess at what you are trying to say; we are not mind readers. Be clear and concise.
  • Spelling and grammar are not rated, but they do make a post easier to read.
See more
See less

Decided to start learnig C

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #76
    I'm assuming the OP is familiar with elementary concepts in computer programming if he/she has coded in BASIC. If so, learning C is a natural next step. I would not recommend it to folks who have never programmed before. Something like Python is better suited for that.

    C's most powerful tool is that of the data pointer. It can do great things and cause great havoc if done wrong. If you can figure those out along with intermediate concepts like structs, linked lists, and recursion, it opens up a ton of doors to problem solving and programming. Whats nice about knowing C is that there are a ton of languages with "C like" syntax (Swift, Java, C#) or directly derived from C (C++, Objective-C, both object oriented extensions) that you can quickly pick up. Having a ton of existing code to play with and compilers on just about every platform is nice too.

    The "flavors" of C mentioned here mostly come from the standard libraries compilers include. The most well known of these is glibc (GNU gcc, *nix) and the Microsoft C Runtime (msvcrt, Visual C++). C libraries back in the day were like the wild west due to the lack of standards, so be careful.

    Comment


      #77
      gcc has quite a number of backends, not just x86. I use it for ARM as well as x86-64.

      Another C to consider that was somewhat popular in its day was D.J. Delorie's DJGPP for writing 32-bit code on DOS without the bother of going to the Windows API.
      Reach me: vcfblackhole _at_ protonmail dot com.

      Comment


        #78
        Just glad I never tried to learn C as the first language.

        A BBC micro was a great place to start. Fairly straightforward basic and the ability to use procedures got the mind working in structure. Once that was learnt, the embedded assembler and the well defined OS calls were next. Wrote a text to speech program in assembler by re-directing the keyboard interrupt , point is from Basic to operating system assembly calls is fairly easy all in one machine with some good books to back it up. Taught me a lot, sat there with the Basic manual open and Ian Birnbaums assembly book, all I needed

        C's pointers would have confused me if I didn't have some sort of understanding of how things worked.

        Would recommend one for kids even now.
        Current fleet
        TRS80 Model 4 - BBC B - Tatung Einstein - PCW9512 - PET 3032 - C64 - ZX81 - Spectrum 48K - Amiga A500 - Apple II europlus - Apple iMAC G3. Sharp MZ-80K. - IBM 5160 XT - Multibus 286/10 - Micro PDP 11/73 - Rainbow PC100A - MicroVax II - MicroVAX 3100, 3300, VAX 4000 VLC & 4000 Model 96 - AlphaStation 225 Apricot PC - Apple Performa 6200 - Apple Mac IIcx - Osborne 1 - ACT Sirius 1

        Comment


          #79
          A C pointer is hardly different from an assembly pointer with the exception of the compiler enforcing typing. It's a pretty fundamental concept in CS

          Comment


            #80
            Pointers are darned useful in the real world. FORTRAN for years tried to avoid them, but finally gave in.

            In the BASIC that I did for an 8085 system, I invented the "BASED" keyword to denote an array or string that had no initial address assignment.

            You could then say "BASE A$ AT FOOF$(3)" whence A$ would refer to the third element of FOOF$. So pointers without explicit pointers.

            I might note (patting myself on the back) that this was long before the Microsoft C++ "__based" declaration.
            Reach me: vcfblackhole _at_ protonmail dot com.

            Comment


              #81
              A funny thing about C pointers is that you can write using them or write not using them and often a compiler is smart enough to emit optimimized code either way.

              Here is an example:

              Code:
              char *p;
              
              for (p=string ; *p; p++)
                putc(*p);
              vs.

              Code:
              int i1;
              
              for (i1=0; string[i1]; i1++)
                putc(string[i1]);
              Perhaps this is just an example of using a pointer to iterate vs. directly indexing an array using an integer. One needs to understand pointers when passing to functions, etc. as well.

              Comment


                #82
                Recently I discovered how c / c ++ compiler „sees” array syntax.
                Code:
                #include <stdio.h>
                
                int main()
                {
                	char a[] = { "run" };
                	*a = 2[a];     // :)
                	printf( "%s", a );
                	return 0;
                }
                Interestingly, none of my professional ( c#, c++, python, java ) programmer friends knew why it works

                Comment


                  #83
                  Originally posted by Chuck(G) View Post
                  Pointers are darned useful in the real world. FORTRAN for years tried to avoid them, but finally gave in.

                  In the BASIC that I did for an 8085 system, I invented the "BASED" keyword to denote an array or string that had no initial address assignment.

                  You could then say "BASE A$ AT FOOF$(3)" whence A$ would refer to the third element of FOOF$. So pointers without explicit pointers.

                  I might note (patting myself on the back) that this was long before the Microsoft C++ "__based" declaration.
                  So could the 3rd Element of FOOF$ consist of a Word or a single letter?

                  In BASIC, I've noticed String Arrays can consist of a Word, so A$(3)="BLAH!", though say for example you want to extract the 'A' from 'BLAH!', to store elsewhere, p=INSTR(a$(3),"A"):c$=MID$(a$(3),p,1), with INSTR searching and returning a value to variable 'p' to where 'A' was found. INSTR has a 3rd optional parameter which can be a variable with a value in it and INSTR searches from that Position for the next occurance of what it's looking for (useful for searching another occurance of the same letter for example), I don't know if that would be considered the closest thing BASIC has to Pointers though since variables are all global in Locomotive BASIC.
                  Generic and Amstrad CPC based Programs written in Turbo Pascal 3

                  Comment


                    #84
                    Some BASICs have pointers; some don't. Often you'll have the VARPTR and/or STRPTR functions which return a memory address that you can then PEEK and POKE, but (like many things in BASIC) it wasn't part of the original language, so YMMV.
                    Computers: Amiga 1200, DEC VAXStation 4000/60, DEC MicroPDP-11/73
                    Synthesizers: Roland JX-10/SH-09/MT-32/D-50, Yamaha DX7-II/V50/TX7/TG33/FB-01, Korg MS-20 Mini/ARP Odyssey/DW-8000/X5DR, Ensoniq SQ-80, E-mu Proteus/2, Moog Satellite, Oberheim SEM
                    "'Legacy code' often differs from its suggested alternative by actually working and scaling." - Bjarne Stroustrup

                    Comment


                      #85
                      Originally posted by goostaw View Post
                      Recently I discovered how c / c ++ compiler „sees” array syntax.
                      Interestingly, none of my professional ( c#, c++, python, java ) programmer friends knew why it works
                      Is it because it is interpreting the 2 as a memory address? Then using a to index it. Does the output show "n" ?

                      Comment


                        #86
                        In the C standard, a[i] is equivalent to *(a+i). Since addition is commutative, i[a], as it is *(i+a), is equivalent.

                        This is a nice deeper dive: https://en.wikibooks.org/wiki/C_Prog...ers_and_arrays
                        I use my C128 because I am an ornery, stubborn, retro grouch. -- Bob Masse
                        Various projects and oddities: http://oldvcr.blogspot.com/
                        Machine room: http://www.floodgap.com/etc/machines.html

                        Comment


                          #87
                          If you read the book that I referred to in an earlier post (C traps and pitfalls) you can "break" this equivalence by telling the compiler lies. The two are only equivalent if the compiler is effectively 'told that they are' and it can work it out for itself what code to lay down.

                          I have a C/C++ professional trainer colleague that disagreed with me - until we tested it on an SGI/IRIX box and I demonstrated it to be true. The retort was "this must be machine specific and it doesn't work like that on Windows with the Microsoft compiler". So we copied the files over to his laptop - and lo and behold it didn't work either. There then followed an afternoon debugging session to demonstrate that the book is correct! That is now in his training course...

                          Dave

                          Comment


                            #88
                            Or, you could post your example rather than referring to a book I have to go track down, ahem. (Especially if it involves, as you call it, lying to the compiler, which I would consider pathological.)
                            I use my C128 because I am an ornery, stubborn, retro grouch. -- Bob Masse
                            Various projects and oddities: http://oldvcr.blogspot.com/
                            Machine room: http://www.floodgap.com/etc/machines.html

                            Comment


                              #89
                              Originally posted by CP/M User View Post
                              So could the 3rd Element of FOOF$ consist of a Word or a single letter?

                              In BASIC, I've noticed String Arrays can consist of a Word, so A$(3)="BLAH!", though say for example you want to extract the 'A' from 'BLAH!', to store elsewhere, p=INSTR(a$(3),"A"):c$=MID$(a$(3),p,1), with INSTR searching and returning a value to variable 'p' to where 'A' was found. INSTR has a 3rd optional parameter which can be a variable with a value in it and INSTR searches from that Position for the next occurance of what it's looking for (useful for searching another occurance of the same letter for example), I don't know if that would be considered the closest thing BASIC has to Pointers though since variables are all global in Locomotive BASIC.
                              We used a somewhat different notation for strings and substrings. So in our case, the A$(3) refers to the third character of A$. Someday, I'll get into the details on how we notated substrings, etc. No MID$, LEFT$, etc. Made for some nice optimization by the compiler.

                              We also sought to make the whole affair somewhat datatype agnostic. So you could write:

                              A$="3"
                              B=2
                              C=A$+B

                              And the value of C would be 5.
                              Reach me: vcfblackhole _at_ protonmail dot com.

                              Comment


                                #90
                                So it's not C=VAL(A$)+B? Or was A$ previously declared as a numeric somehow"
                                Surely not everyone was Kung-Fu fighting

                                Comment

                                Working...
                                X