- main2(), kernel_main (c/c++) - 17 Updates
- [Jesus Loves You] How'd we become so depraved? - 1 Update
- Most Sacrilegious Code I've Ever Written - 2 Updates
- WxWidgets events question - 5 Updates
G G <gdotone@gmail.com>: Jul 10 11:24AM -0700 is it possible that c/c++ programs can start with something other than a function named main()? or is it somehow set in the compiler the name of the function where to start? http://www.cplusplus.com/articles/zv07M4Gy/ https://github.com/travisg/newos/blob/master/kernel/main.c https://git.haiku-os.org/haiku/tree/src/system/kernel/main.cpp |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Jul 10 07:50PM +0100 > is it possible that c/c++ programs can start with something other > than a function named main()? In what are called free-standing implementations, there need be no main function. This applies to both C and C++. Programs written for hosted implementations must define a main function. > or is it somehow set in the compiler the name of the function > where to start? The "or" is not right. There need not be a main /and/ the name of the function to start is somehow set in the compiler. > http://www.cplusplus.com/articles/zv07M4Gy/ > https://github.com/travisg/newos/blob/master/kernel/main.c > https://git.haiku-os.org/haiku/tree/src/system/kernel/main.cpp Did I need to read these? If there is something at these links which you want people to comment on, it's better to pull out a quote and post that (along with the URL for reference). -- Ben. |
James Kuyper <jameskuyper@alumni.caltech.edu>: Jul 10 02:52PM -0400 On 7/10/19 2:24 PM, G G wrote: > is it possible that c/c++ programs can start with something other > than a function named main()? Since you're explicitly asking about both C and C++, I'm cross-posting this to comp.lang.c. Yes it is possible, but only for freestanding implementations: "In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined." (C standard, 5.1.2p1) "It is implementation-defined whether a program in a freestanding environment is required to define a main function." (C++ standard, 6.6.1p1). > or is it somehow set in the compiler the name of the function > where to start? An implementation of C or C++ can conform either as a freestanding implementation or a hosted one. A hosted implementation must recognize main() as the starting point. A freestanding implementation may have other ways of identifying the starting point, but is required to document them, and (implicitly) is required to conform to whatever documentation it provides. Either way, it is indeed up to the implementation to recognize the permitted ways of identifying the starting point of a program. It is common, but not essential, for an implementation to be divided into several separate parts, such as a pre-processor, a compiler, and a linker. However, the standard says nothing about how the work of an implementation should be sub-divided. It is only the implementation as a whole that has responsibility for implementing the correct start point for a program. That being said, in a typical pre-processor/compiler/linker setup, it is indeed the compiler that is required to recognize the start point, but it's the linker that actually does what's needed to make the program start there. |
David Brown <david.brown@hesbynett.no>: Jul 10 08:54PM +0200 On 10/07/2019 20:24, G G wrote: > is it possible that c/c++ programs can start with something other > than a function named main()? Yes. > or is it somehow set in the compiler the name of the function > where to start? On gcc, you can use the "--entry" option. Using something other than main will be non-standard for hosted implementations, but is sometimes used in free-standing (bare metal) implementations where your code runs directly from the power-on reset. But even there, there is seldom good reason to pick a different name - it just risks confusion and possible inconsistencies. |
G G <gdotone@gmail.com>: Jul 10 12:16PM -0700 = > that (along with the URL for reference). > -- > Ben. no, but, i didn't know if someone needed to see an example of what i was talking about |
Keith Thompson <kst-u@mib.org>: Jul 10 01:08PM -0700 James Kuyper <jameskuyper@alumni.caltech.edu> writes: [...] > indeed the compiler that is required to recognize the start point, but > it's the linker that actually does what's needed to make the program > start there. I don't believe the compiler is required to recognize the entry point. Under gcc, for example, it appears to be just another function. When I compile these two functions: int main(void) { return 0; } and int notmain(void) { return 0; } with "gcc -S", the assembly listings are identical other than the function name. It's the linker that recognizes "main" as the entry point. The compiler does recognize "main" so it can generate code equivalent to "return 0;" if control reaches the closing "}"; I deliberately avoided that in my examples. But a conforming compiler could just do that for all int functions. -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */ |
Bart <bc@freeuk.com>: Jul 10 09:59PM +0100 On 10/07/2019 19:24, G G wrote: > than a function named main()? > or is it somehow set in the compiler the name of the function > where to start? It depends on compiler+linker. On my C implementation, I can use the entry point "start" as well as "main". And with some extra effort, any function can be used as an entry point. But if I wanted the starting function to take the argc/argv parameters commonly used with main(), then the name has to be "main", as only for that name will the compiler make arrangements for those to be set up. (This is for Windows; the arrangements for Linux may be different.) Other implementations may have additional initialisations that have to be done on start-up, and those can be associated with "main" in the same way. |
Juha Nieminen <nospam@thanks.invalid>: Jul 10 09:53PM >> or is it somehow set in the compiler the name of the function >> where to start? > On gcc, you can use the "--entry" option. You can also use -nostartfiles, which gives you a much more barebones executable. Rather than main(), a function with the signature void _start() (no parameters) will be called at startup. (The proper way to end the program in this situation is to call exit(). I'm not sure what happens if the _start() function just ends. Maybe it crashes or something.) You'll have a much harder time getting any command-line parameters, but in many programs they aren't actually needed. |
Melzzzzz <Melzzzzz@zzzzz.com>: Jul 10 09:58PM > function just ends. Maybe it crashes or something.) > You'll have a much harder time getting any command-line > parameters, but in many programs they aren't actually needed. _start is default for ld, you can also change that. Command line parameters on Linux are on stack so you have to do it with inline assembly or enter territory of UB. -- press any key to continue or any other to quit... U ničemu ja ne uživam kao u svom statusu INVALIDA -- Zli Zec Na divljem zapadu i nije bilo tako puno nasilja, upravo zato jer su svi bili naoruzani. -- Mladen Gogala |
David Brown <david.brown@hesbynett.no>: Jul 11 09:28AM +0200 On 10/07/2019 22:08, Keith Thompson wrote: > equivalent to "return 0;" if control reaches the closing "}"; > I deliberately avoided that in my examples. But a conforming > compiler could just do that for all int functions. I believe some C++ compilers have special treatment for a function called main(). For both C and C++, there are things that need to be done before main() starts. For C, this means zeroing uninitialised static data, copying initialised data, and setting up the arguments for main(), and afterwards calling atexit functions. For C++, global constructors need to be called and possibly code for initialising other global data - and at the end, global destructors must be called. On some systems, the link/loader can do all that is needed for C. On other systems, it is done by part of the C library - the actual entry point of the code is called something like "__startup" and is part of the library that is included in the application binary. For C++, you always need something like that. But on some compilers I have seen, this startup and breakdown code is injected directly into the "main" function by the compiler. |
David Brown <david.brown@hesbynett.no>: Jul 11 09:31AM +0200 On 10/07/2019 23:53, Juha Nieminen wrote: > function just ends. Maybe it crashes or something.) > You'll have a much harder time getting any command-line > parameters, but in many programs they aren't actually needed. You usually use this sort of thing in very small systems embedded programming. You don't have a command line, much less command-line parameters, and your _start() function never ends because you invariably have an infinite loop in your main code. I have only once needed --nostartfiles, for programming a microcontroller with no ram at all. It had 32 8-bit cpu registers, and a three level hardware call stack. Having _start() call main() would have wasted at least a third of the resources of the cpu! |
Martijn van Buul <pino@dohd.org>: Jul 11 02:59PM * David Brown: > microcontroller with no ram at all. It had 32 8-bit cpu registers, and > a three level hardware call stack. Having _start() call main() would > have wasted at least a third of the resources of the cpu! My crystal ball predicts that this was an ATTiny 1x device. -- Martijn van Buul - pino@dohd.org |
Keith Thompson <kst-u@mib.org>: Jul 11 02:14PM -0700 > http://www.cplusplus.com/articles/zv07M4Gy/ > https://github.com/travisg/newos/blob/master/kernel/main.c > https://git.haiku-os.org/haiku/tree/src/system/kernel/main.cpp Is there something specific you're trying to accomplish by having your program start with a function other than main(), or are you just asking out of curiosity? (Nothing wrong with the latter, but it could affect what kind of answer is going to be useful to you.) Note that there's really no such thing as "c/c++". C and C++ are two different languages. They're closely related, and they have similar (but not identical) rules in this area, but it's not clear that the answer is going to be the same for both. -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */ |
G G <gdotone@gmail.com>: Jul 11 05:20PM -0700 > your program start with a function other than main(), or are you > just asking out of curiosity? (Nothing wrong with the latter, but > it could affect what kind of answer is going to be useful to you.) asking out of curiosity, yes, and when looking at some very large programs, operating systems' source code and a few application i was not finding a main(). some were C programs some were C++ programs. PostgreSQL, FreeBSD, Haiku OS, NewOS, ... > Note that there's really no such thing as "c/c++". C and C++ are > two different languages. yes, they are. here "c/c++" is only about asking C or C++ programming language. They're closely related, and they have > similar (but not identical) rules in this area, but it's not clear > that the answer is going to be the same for both. Ah, yes. James pointed that out. I am currently studying C++, and Operating Systems Design and Implementation and M68000 assembly language. the m68000 i know is old, but the book i found is old, was cheap, and looks and reads great. And thanks Keith, i hope many of you all take part in An OS group, cause i do have a few questions. :-) ok way more than a few. |
Martijn van Buul <pino@dohd.org>: Jul 12 07:20AM * G G: > and M68000 assembly language. > the m68000 i know is old, but the book i found is old, was cheap, and looks > and reads great. Just out of curiousity: Which revision of that book are you reading? -- Martijn van Buul - pino@dohd.org |
David Brown <david.brown@hesbynett.no>: Jul 12 09:37AM +0200 /Please/ keep the standard Usenet attributions! On 12/07/2019 02:20, G G wrote: > I am currently studying C++, and Operating Systems Design and Implementation > and M68000 assembly language. The m68k ISA is a really nice design. The original 68000 was very forward-looking - it was designed with a clear expansion path in the future, contrasting with the x86 architecture which was an outdated style almost when it started, and has been a continuous process of patches, hacks and add-ons. If you want to learn some assembly, then it is definitely one to recommend - even though it is not much in active use. (It is used in ColdFire microcontrollers, which are still available but are no longer being developed for the future.) |
G G <gdotone@gmail.com>: Jul 12 12:57AM -0700 On Friday, July 12, 2019 at 3:21:10 AM UTC-4, Martijn van Buul wrote: > Just out of curiousity: Which revision of that book are you reading? > -- > Martijn van Buul - pino@dohd.org sure, Assembly Language and Systems Programming for the M68000 Family copyright 1992 looks like the second edition of the book, cause it makes mention the previous edition. |
gazelle@shell.xmission.com (Kenny McCormack): Jul 11 04:59PM In article <qd0rlv$uep$1@gioia.aioe.org>, <johnbenny@nowhere.co.uk> wrote: ... >Its sad an obviously otherwise intelligent man like yourself believes all >these fairy stories. I disagree that Ricky is an "otherwise intelligent man". As F. Gump says, and I agree wholeheartedly, "Stupid is as stupid does". Translation: If you consistently behave stupidly, you are stupid. >To you they must seem like potentious words of wisdom but to the >rest of us they're just laughably simplistic just-so tales meant for >illiterate uneducated donkey riding peasents 2000 years ago. They work equally well for illiterate uneducated donkey riding peasents today (like Ricky, and many others). -- Genesis 2:7 And the LORD God formed man of the dust of the ground, and breathed into his nostrils the breath of life; and man became a living soul. |
cauldwell.thomas@gmail.com: Jul 11 01:53AM -0700 Hi guys it's Frederick from 15 years ago. I work fulltime as a firmware engineer now. I think today I wrote the most sacrilegious code I've ever written. struct Param { struct Dummy { operator unsigned() { return 0; } operator void*() { return 0; } }; Dummy operator&() const { return Dummy(); } }; |
"Öö Tiib" <ootiib@hot.ee>: Jul 11 07:52AM -0700 On Thursday, 11 July 2019 11:53:57 UTC+3, Frederick Gotham wrote: > return Dummy(); > } > }; Common reason of overloading address of operator is that then we can handle objects that are masquerading as (for example because of being proxy to) some other objects more conveniently and/or more confusingly. Your Parameter seems to be proxy to nothing. I don't see how it can be useful even in unit test. OTOH big part of C++ code out there is useless so it is not sacrilegious to write some more. |
Szyk Cech <szykcech@spoko.pl>: Jul 10 05:37PM +0200 > What isn't very wise is using WxWidgets instead of Qt From my point of view Qt is far from ideal C++ library: - You can't write mobile apps in C++ - because they force to use vendor lock QML (JavaScript style) language. WHEN I REALIZE THIS I DECIDE TO SPLIT UP WITH QT!!! - Broken properties: you declare them in C++ but you can use them only in script languages - Error handling by return value instead by exceptions. - Broken classes created with rule: "Closed for modifications and close for extendability" - so you can't make wrapers for stupid error tracking to use comfortable exceptions (especially in SQL apps). This is mainly due to lack virtual destructors and minor due to non virtual members in most cases. - Many classes are broken by design: you want to create fully featured QTreeView? You should be prepared for writing 1000 lines of code to make it. You want access function in QMenu which emulate key pressing - to raise menu programmically?!? Forget about this idea! - They claim Qt is modular == composed from many independent libraries, but you can't even write modular programmer text editor with Qt: due to broken QTextEdit: you can't define 2 syntax highlighter at the same time - but it is expected from modular approach to create one plugin for syntaxhighlighting, and other for spell checking. More: You can't attach more that one object to QTextBlock (which store one line of code in QTextEdit), this cause that it is impossible to have one plugin for syntax highlighter and other for bookmarks (switchable marked places in code - you can jump between them by hit keyboard shortcuts). So you can have modular program with syntax highlighting or with bookmarks but not at the same time! - Communication with QWebEngine (JavaScript <-> C++) is piece of madman solution. To sum up: After selling Qt to Nokia things are going worse and worse. I don't expect any significant improvement in approaching Qt 6. They don't have the same philosophy as they have before Qt 4 (easy to use library for writing apps in pure C++). How ever until Nokia days Qt has only commercial license for commercial projects. |
legalize+jeeves@mail.xmission.com (Richard): Jul 10 04:58PM [Please do not mail me a copy of your followup] leigh.v.johnston@googlemail.com spake the secret code >What isn't very wise is using WxWidgets instead of Qt given that >WxWidgets is an egregious rip off of the disaster that is MFC. Of course >once neoGFX 1.0 is released using Qt will also be unwise. :) What isn't very wise is using Qt instead of WxWidgets given that Qt is an egregious rip off of the disaster that is NIH syndrome. In all seriousness, though, Qt and WxWidgets take very different approaches to the same problem. Qt implements the entire GUI stack and just subscribes to events from the underlying window system and pushes pixels in return. (This is why you can run a Qt application on Windows with a command-line switch that says "give me the macOS look and feel".) WxWidgets acts as the thinnest possible portable layer on top of the native windowing system. This is why WxWidgets applications manage to maintain exactly look and feel of the native window system, while Qt applications have minor quirks and differences that are noticeable to experienced users. It is also why WxWidgets applications have significantly smaller footprints -- instead of reimplementing the GUI stack, they sit on top of the native GUI stack. Oddly enough, the latest WxWidgets can even sit on top of Qt for environments where Qt has a windowing system implementation and WxWidgets does not. Although personally I consider that to be a weird solution, but obviously someone found it useful or they wouldn't have contributed the implementation. I've worked on non-trivial WxWidgets applications (subdivision surface modeler) and non-trivial Qt applications (3D scene composition and rendering). Both frameworks have their advantages and disadvantages. My personal preference is for WxWidgets because it is a lighter layer and matches the native windowing system more faithfully because it doesn't try to reinvent the entire look and feel itself. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Terminals Wiki <http://terminals-wiki.org> The Computer Graphics Museum <http://computergraphicsmuseum.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 10 06:25PM +0100 On 10/07/2019 17:58, Richard wrote: > My personal preference is for WxWidgets because it is a lighter layer > and matches the native windowing system more faithfully because it > doesn't try to reinvent the entire look and feel itself. Wrong. Matching the "native" widget system is a bad idea: if the "native" system doesn't offer a feature that your application needs on a particular OS then you have two choices: 1) bodge your application for that particular OS or 2) use a non-native widget system that has the same, consistent look and feel no matter what OS it is running on. Modern frameworks usually employ skins so you can at least get the look of native widgets if not the feel. /Flibble -- "Snakes didn't evolve, instead talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
"Öö Tiib" <ootiib@hot.ee>: Jul 10 03:05PM -0700 On Wednesday, 10 July 2019 18:37:52 UTC+3, Szyk Cech wrote: > - You can't write mobile appqts in C++ - because they force to use vendor > lock QML (JavaScript style) language. WHEN I REALIZE THIS I DECIDE TO > SPLIT UP WITH QT!!! Usage of GUI scripting with QML is not anyhow forced by it. The sole C++ application toolkit in existence with what we can write GUI programs that compile and run as native applications for OSX, iOS, Android, Windows and Linux is Qt. QML just works on all those platforms if we want that feature. Seems that you are one of those Dunning-Kruger types who is hugely ignorant but wants to teach others from that miserable state. |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 10 11:56PM +0100 On 10/07/2019 23:05, Öö Tiib wrote: > platforms if we want that feature. > Seems that you are one of those Dunning-Kruger types who is hugely > ignorant but wants to teach others from that miserable state. Qt Company's primary product marketing on their website puts QML front and centre so that is rather telling as to what their primary focus is. My (neoGFX) scripting support will be entirely optional in the primary work flow. Yes Qt is currently the *least worst* offering as far as a cross platform C++ GUI library is concerned but I intend to improve on that sorry state of affairs with neoGFX. /Flibble -- "Snakes didn't evolve, instead talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment