OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Sep 21, 2019 7:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 3:36 am 
Offline
Member
Member

Joined: Fri Jul 11, 2008 5:15 am
Posts: 342
Location: Hungary
JohnnyTheDon wrote:
#define is also nice when you need to define a lot of numerical constants.


That can be done using the const modifiers. Any sane compiler will recognize it's a constant value, and will not generate a memory access for the variable, it will simply inline the value.
But I agree doing it with preprocessor macros looks nicer.


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 3:47 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7412
Location: Germany
Code:
#define MAX_BRAIN_CELLS 42

size_t const MAX_BRAIN_CELLS 42:

enum
{
    MAX_BRAIN_CELLS = 42;
}


The effect of the three is more or less identical. I prefer #2, because it's the only one that actually is straightforward and typesafe.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 1:53 pm 
Offline
Member
Member

Joined: Sun Nov 09, 2008 2:55 am
Posts: 524
Location: Pennsylvania, USA
ru2aqare wrote:
JohnnyTheDon wrote:
#define is also nice when you need to define a lot of numerical constants.


That can be done using the const modifiers. Any sane compiler will recognize it's a constant value, and will not generate a memory access for the variable, it will simply inline the value.
But I agree doing it with preprocessor macros looks nicer.


GCC isn't sane then. It exports the const variables, causing a bunch of multiple definitions. Also, when declaring global or stack arrays const variables cannot be used.


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 8:05 pm 
Offline
Member
Member

Joined: Wed Oct 18, 2006 3:29 pm
Posts: 202
JohnnyTheDon wrote:
ru2aqare wrote:
JohnnyTheDon wrote:
#define is also nice when you need to define a lot of numerical constants.
That can be done using the const modifiers. Any sane compiler will recognize it's a constant value, and will not generate a memory access for the variable, it will simply inline the value.
But I agree doing it with preprocessor macros looks nicer.
GCC isn't sane then. It exports the const variables, causing a bunch of multiple definitions.

That they are exported doesn't mean they are not inlined in the current module. Also, to avoid that you can always declare them as static const (possibly in the header).
There's also a way I'm sure GCC inlines your constant. Inter-module analysis is achieved in GCC by feeding everything into it at once, and running with -O3 -fwhole-program -combine. Once, I did it on a university work and the boy inlined everything into a HUGE main(). I doubt this mass-inlining approach is always an intelligent optimization, however.

Quote:
Also, when declaring global or stack arrays const variables cannot be used.

Did not remember that. In fact, in C this doesn't work.
However, in a modern language, you don't have to fear this limitation. In Java, you can put non-constant initializers in attributes (including static ones, afaik), and I guess you can do this in D and in C# either.

Alas, IMHO C has a very important role as a relatively low-level language, specially in operating system development (as all of you know). I think it would be a fairly good idea to redesign the language, not to bloat it and to add every imaginable feature, but just to modernize it. Removing that old header-inclusion scheme and that type-unsafe preprocessor, and instead rely on the compiler to optimize away unneeded code and function calls would help a lot. Adding namespaces and a template facility would also be a good idea.
Redesigning setjump/longjump in order to make it easer to implement threading libraries and SEH libraries without assembly code would be a good idea, too.
Personally, I don't like very much the C syntax. But killing would be a nasty idea. People love it. :-)

I don't think it would be easy, though. There are also a bunch on C dialects out there, and non of them has the goal of cleaning-up the original language, so I don't think there are many people inclined to this kind of redesign to the language.

JJ


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 8:17 pm 
Offline
Member
Member

Joined: Wed Oct 18, 2006 3:29 pm
Posts: 202
JohnnyTheDon wrote:
That isn't allways true. There are some things (like conditional compilation) that can't be done w/o the preprocessor, at least not in a sane way.

I forgot to comment this.
This point, once again, should be done by the compiler. See: You create your static const value and then you employ and if() around the code that will be the subject of the conditional compilation.
At compile time, the static const gets inlined by the optimizer, which then observes that the if is always true/false and optimizes away the extra code.

If you are worried about legibility, then syntactic sugar could be used. There could be, for example, a capitalized IF() or a IFDEF(), semantically equivalent to if(), but intended to be used, by convention, for conditional compilation.

This solution has also the advantage that if you wanted, e.g., to compile a kernel that would use SSE instructions on machines supporting SSE, but would not crash on machine without SSE support, you could just remove the const and set the variable on initialization.

JJ


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 8:22 pm 
Offline
Member
Member

Joined: Sun Nov 09, 2008 2:55 am
Posts: 524
Location: Pennsylvania, USA
Quote:
I think it would be a fairly good idea to redesign the language, not to bloat it and to add every imaginable feature, but just to modernize it.


This is what D tried to do. It actually declares itself as a systems programming language, but kind of falls short. IMHO, anything with a GC is going to be unreliable for systems programming, at least in the kernel.


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 10:21 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 29, 2008 1:07 pm
Posts: 550
Location: Throw a dart at central Texas
One feature I wish this forum had is to put any code above a certain size into it's own "frame" so that code dump posts aren't 6 miles long. It's really quite easy, just add "max-height: Xpx; overflow: auto" to the code tag's css/style. IIRC there were a few display problems getting it working on my site, though.

_________________
Owner of Fawkes Software.
Wierd Al wrote:
You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 11:44 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2097
Location: Bucharest, Romania
This already happens.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 22, 2009 11:55 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 29, 2008 1:07 pm
Posts: 550
Location: Throw a dart at central Texas
Under which themes? It would be nice if the default theme did this to, as that's the one I prefer.

_________________
Owner of Fawkes Software.
Wierd Al wrote:
You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Fri Jan 23, 2009 11:14 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 3:29 pm
Posts: 202
JohnnyTheDon wrote:
Quote:
I think it would be a fairly good idea to redesign the language, not to bloat it and to add every imaginable feature, but just to modernize it.

This is what D tried to do. It actually declares itself as a systems programming language, but kind of falls short. IMHO, anything with a GC is going to be unreliable for systems programming, at least in the kernel.


The problem with that approach is, if you add GC, then you are adding a core feature (and in this case, it's a fairly expensive one).
No. I think a C replacement must be based on the same simplistic principles as C. Traditional procedural programming, minimalistic standard library, data manipulation similar to the asm programmer's usual approach (e.g. strings being just arrays of characters), minimalistic abstractions imposed by the language, no GC, classical pointers, no exceptions, no additional runtime support required for the basic language constructs apart from the usual stub that calls main(), easily optimizable for speed, etc. Additional features could then be added as extensions, or as a PlusPlus variant of the language, but the base being simple, while still fixing some of the longstanding C flaws.

About what I called "templates" in the last post, I meant something like "parametric namespaces", where the namespace could be "imported" and accessed with different parameters. Those parameters could be either integers or pointers. This would help implementing e.g. linked lists, because the compiler would just have to reserve the needed space where the parameter type is unknown at compile time.

JJ


Last edited by JJeronimo on Fri Jan 30, 2009 7:35 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Fri Jan 23, 2009 11:39 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2097
Location: Bucharest, Romania
Firestryke31 wrote:
Under which themes? It would be nice if the default theme did this to, as that's the one I prefer.


It works just fine for me under the default theme. Let's check again:

Code:

























































EDIT: yep, it looks just fine here...

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Fri Jan 23, 2009 12:44 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 29, 2008 1:07 pm
Posts: 550
Location: Throw a dart at central Texas
Subsilver 2 doesn't. Relevant CSS:

Code:
.codecontent {
   direction: ltr;
   margin: 0 5px 10px 5px;
   padding: 5px;
   border-color: #A9B8C2;
   border-width: 0 1px 1px 1px;
   border-style: solid;
   font-weight: normal;
   color: #006600;
   font-size: 0.85em;
   font-family: Monaco, 'Courier New', monospace;
   background-color: #FAFAFA;
}


Could be changed to:
Code:
.codecontent {
   direction: ltr;
   margin: 0 5px 10px 5px;
   padding: 5px;
   border-color: #A9B8C2;
   border-width: 0 1px 1px 1px;
   border-style: solid;
   font-weight: normal;
   color: #006600;
   font-size: 0.85em;
   font-family: Monaco, 'Courier New', monospace;
   background-color: #FAFAFA;

   max-height: 400px;
   overflow: auto;
}


Edit: When I said "default" theme, I meant the one guests see, which is the one set when I registered.

_________________
Owner of Fawkes Software.
Wierd Al wrote:
You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Sat Jan 24, 2009 10:03 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2423
Location: Canada
It doesn't work on the MegaTokyo theme.. which, IMHO, should be the default. ;)

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
UNIX&BSD's, your only aspirations, to be imitated! 8)
Windows, are an opening in an otherwise solid and opaque surface through which light and, sometimes, even air can pass through; nothing more.


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Mon Jan 26, 2009 5:20 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2000
Location: USA (and Australia)
There are times when the preprocessor is useful. I wrote an event system and I had a file called EVENTS.H which basically contained:

Code:
DEFEVENT(MouseMove, (int x, int y))
DEFEVENT(MouseButtonDown, (int button))
DEFEVENT(MoseButtonUp, (int button))
// insert 50 or so relevant events


and each time I included EVENTS.H DEFEVENT(name, params) was defined to something different. (e.g. first time it would define fireMouseMove(int x, int y)), second time it would create an array of each object listening to that event, and third time it would create a virtual function called void onMouseMove(int x, int y)). A lot of other stuff was also preprocessed (register that the object listens for an event).

I'm sure there could have been a better way to do it, but it was designed to add/remove lots of events easily.

_________________
My OS is Perception. (1 2)


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 29, 2009 1:55 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
What about using the preprocessor to increase speed of the program, and ease on the developer?

I discovered the C preprocessor was capable of this nifty little thing earlier yesterday.
Code:
#define PANIC(x)\
   epbp_panic(x,__FILE__,__FUNCTION__,__LINE__)

With this, I get where the panic occured in my code, and the code(x) for the panic. Before I knew of this, I had to either type that huge long line, or just use codes, which didn't tell me exact information.

the preprocessor is very handy in the hands of those that know how to use it. But, it can be easily abused too.

edit:
Is there any way to do this in your precious D? I didn't see any replacement for such a macro in that C preprocessor vs. D link...

_________________
My new NEW blag


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group