mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2016-01-09, 03:21   #1
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts
Default Modern C

https://matt.sh/howto-c

I got around halfway through it before getting bored, and in the first half, about the only thing I didn't already know was dedicated pointer arithmetic types. (Admittedly, I do have reasonably substantial experience on a modern C99 codebase where most of these tips are already standard practice.)
Dubslow is offline   Reply With Quote
Old 2016-01-09, 09:20   #2
Nick
 
Nick's Avatar
 
Dec 2012
The Netherlands

24·101 Posts
Default

That's the first website I've ever visited on St. Helena (if it's really there)!
Nick is offline   Reply With Quote
Old 2016-01-09, 09:42   #3
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
Jun 2011
Thailand

5·17·109 Posts
Default

Quote:
Originally Posted by Nick View Post
That's the first website I've ever visited on St. Helena (if it's really there)!
It is not. The second-level is not a valid one (from the seven), it is used for short-cuting the links, same like fold.it or isup.me
LaurV is offline   Reply With Quote
Old 2016-01-09, 12:31   #4
rogue
 
rogue's Avatar
 
"Mark"
Apr 2003
Between here and the

22·7·223 Posts
Default

I learned a few things, although I don't know how much of it I would use. The company I work for was stuck on C89 coding because their standards were based on K&R C. Most employees were told to buy the book and code to the standards in that. Yuck! I convinced them to support C99 even though M$ doesn't officially support in VisualStudio . All I really wanted was the ability to use // comments. Yes, we had coding standards that forbade // style comments because there are some ancient compilers that don't support them. Interestingly nobody could provide a single example of a compiler that didn't support // style comments past the turn of the century. Note that our internal standard change finally occurred around 2009.

I slightly disagree about the memory allocation one with double pointers (aka handles). If an application cannot allocate the memory it needs to function, there is nothing wrong with just terminating the application rather than bubbling some error up the call stack.
rogue is offline   Reply With Quote
Old 2016-01-09, 15:41   #5
bgbeuning
 
Dec 2014

FF16 Posts
Default

Does C still let you call a function without declaring it first?
We used to get errors like

Code:
int ten() { retrun (10); }
link error: retrun undefined
The only feature I saw not included in C++ is the Variable Length Arrays.
bgbeuning is offline   Reply With Quote
Old 2016-01-09, 23:20   #6
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

2×3×1,579 Posts
Default

Quote:
Originally Posted by bgbeuning View Post
Does C still let you call a function without declaring it first?
Generally, no.

Quote:
Originally Posted by bgbeuning View Post
We used to get errors like

Code:
int ten() { retrun (10); }
link error: retrun undefined
Was retrun() a function you defined, or did you mean return()?
chalsall is online now   Reply With Quote
Old 2016-01-10, 00:25   #7
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

160658 Posts
Default

I think he meant the typo of the keyword "return" did not cause a compilation error, because using undeclared functions was allowed (resulting in the link error since the function doesn't actually exist). He of course meant to use the return keyword. (This sort of thing is one argument in favor of *not* using parens with keywords like "return" and "sizeof", though most people including myself still use parens for the latter.)
Dubslow is offline   Reply With Quote
Old 2016-01-10, 14:38   #8
Nick
 
Nick's Avatar
 
Dec 2012
The Netherlands

65016 Posts
Default

See also: the International Obfuscated C code Contest
http://ioccc.org/
Nick is offline   Reply With Quote
Old 2016-01-10, 22:30   #9
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

2·3·1,579 Posts
Default

Quote:
Originally Posted by Dubslow View Post
I think he meant the typo of the keyword "return" did not cause a compilation error, because using undeclared functions was allowed (resulting in the link error since the function doesn't actually exist). He of course meant to use the return keyword.
Ah... Thanks. Stupid (human) interpreter error...

But at least (even in the olden days before functions had to be pre-declared) the tool chain threw an error before an executable was created. As opposed to, for example, pointer errors or array overruns which the compiler and linker can't catch.

Remember the old saying: "C. All the power, and all the safety features, of a chain saw (or high explosives).
chalsall is online now   Reply With Quote
Old 2016-01-11, 10:33   #10
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

3×3,529 Posts
Default

Quote:
Originally Posted by chalsall View Post
Remember the old saying: "C. All the power, and all the safety features, of a chain saw (or high explosives).
OTOH

When I find my code in tons of trouble,
Friends and colleagues come to me
Speaking words of wisdom:
Write in C.
xilman is offline   Reply With Quote
Old 2016-01-11, 13:56   #11
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

2×3×1,579 Posts
Default

Quote:
Originally Posted by xilman View Post
Write in C.
Please don't get me wrong; I _love_ C.

But it's not for the faint of heart, nor hairless of chest....
chalsall is online now   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modern parameter choice for large 14e/small 15e projects VBCurtis Factoring 29 2016-02-12 20:45
Modern Foreign Languages in schools f1pokerspeed Soap Box 10 2013-12-28 16:27
Still modern? Unregistered Information & Answers 15 2010-07-21 14:14
Chance to use modern Graphics Cards as.. Marco Hardware 28 2003-11-02 23:21

All times are UTC. The time now is 22:58.

Fri Feb 26 22:58:52 UTC 2021 up 85 days, 19:10, 0 users, load averages: 2.04, 2.37, 2.53

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.