Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What will this C code do?

Name: Anonymous 2012-01-19 8:24

void main(){
int x=1;
printf("%d\n",x=2);
}

Name: UTF-8 2012-01-19 19:07

>>38-39
Hi guys, how's it hangin'?

Name: Anonymous 2012-01-19 20:33

Hosted?

// void main(void) is bad because..?

Name: Anonymous 2012-01-20 13:21

>>42

Hosted is a word that refers to C implementations that have a full library (the opposite is "freestanding"). In freestanding C, there may not be a supported startup function called main, and there is no standard in this are. For instance, the Linux kernel does not start with int main(int argc, char **argv). It uses gcc as a freestanding implementation (no standard library either, just pieces of it the kernel provides for itself).  Hosted C implementations can support additional ways for writing the startup function beside the standard one. (E.g. Windows has WinMain).

void main(void) is "bad" because it is a poor tradeoff. you're leaving the standard dialect of C, without getting anything in return (and void is one letter more than int so you don't even save typing). The only exception would be that you need to program some system which for some reason only accepts void main.

void main is cluelessly used by programmers without checking that it is supported  on systems where it isn't actually documented as a valid startup function. it just works by fluke, and usually leaves the program with a garbage termination status, too, if the program stops by running off the end of main instead of calling exit.

Name: Anonymous 2012-01-20 18:35


            :ohmmmhs/`                                                                                                 
         `+mMNy+//+yNmo`                                                                                               
        -dMNo`      .yMh                                                                                               
       -mMd-         `yo   os-                                                                                         
       dMm.              .hMm:                                                                                         
      .MMs              :mMh.                                                                                          
      `mMh`            +NMs`       `os-                                                                                
       -dMh/.        `yMMMy:`     .hMm-                                                                                
        `/hmmdyy+   -dMd-+hmms:` :mMh.   `oo-`                                                                         
           .-/+/.  /NMy`   .+hmmyNNo`   .hMmmdo-`                                                                      
                  sMN+        :NMm:    /mMy..+hmdo-                                                                    
                  :o:        :mMh.   `oNNo`    .+h+                                                                    
                            +NMs`   .hMNNo-`                                                                           
                           sMN/    :mMh-+hmdo.      .:osso/-`                                                          
                           :o-   `+NMs`   .+h+   `/hNNdyyydNdo`                                                        
                                 sMMo           -hMNs-`    -sNd-                                                       
                                 -smmy/.       :NMd-         +N/  `/.                                                  
                                   `:smmy/    .NMd`           .  -mMh                                                  
                                      `:so    oMM-              /NMy`     `                                            
                                              +MM-            `sMN+ ``-/oydy:                                          
                                              `hMm:`         .dMNsoydmNmho/:`                                          
                                                +dNds+/:.   /NMyyMN+:-`                                                
                                                  -+syhs`  oMNo +MN                   `-:                              
                                                         .hMm:  /MM`               /sdNdo.                             
                                                         :hh.   -MM.              hMMo.   `-`                          
                                                                .MM:              ./-    .dMNy/`                       
                                                                `NM+                    /NMy:sNNy/`                    
                                                                 .+-                   sMM+    :sNN-                   
                                                                                     .dMMs`      ``   .:`              
                                                                                    :NMhsmNy/`       /NMNy             
                                                                                   oMMo  `:smm.    `yMNhMN`            
                                                                                 `hMN:      ``    .dMd.dMs             
                                                                                 -hNNo-          /NMy`-MM-             
                                                                                   .+hNdo-     `sMN+  yMd        .+hmy/
                                                                                     `.+hm:   .hMm-  `MM/     .+hNmhMMh`
                                                                                        ``   :mMy`   oMN`  ./hNms:+NMs`
                                                                                             /h+    `mMs./yNmy:``sMN/  
                                                                                                    /MMdmmy/.  .hMd-   
                      .......`         `..         ..     `......`      `..........`                oNNh/.    :mMy`    
                     .mNdhhhdddy/`     +Nm        `NN:    dNmhhhdmdo`   ohhhhhhhdNNy                `..     `oNNo`     
                     .MM/```.-+dMm/    +MM        .MM/    NMs```.:NMy   ```````-hMm-                       `yMm:       
                     .MM:      `sMN:   +MM        .MM/    NMs     yMm         .dMh.                        `oy.        
                     .MM:       `mMh   +MM        .MM/    NMs...-+Nm/        :mMs`                                     
                     .MM:        hMm   +MM        .MM/    NMmddddNMh:`      +NN+                                       
                     .MM:        mMh   +MM        .MM/    NMs....-+NMs    `sMm:                                        
                     .MM:       +MM:   /MM-       /MM-    NMs      sMM`  .dMh.                                         
                     .MM/  ```-sNN+    `dMm:`````/mMy     NMs   ``-mMh  :mMy.```````                                   
                     .NNdhhhhdmdo.      `omNmdhdmNd+`     mNmhhhhdmdo`  mNNddddddddd.                                  
                      -:::::-.`           `-:///:.        -::::::-.     -:::::::::::                                   

Name: Anonymous 2012-01-20 18:39


                                                              omNNm/                  -hNNNh                           
                                                            `yMNmMM+                 :NMmMMN                           
      -h+-`                   -h+-`                        .hMm:hMM+                +NMs:MMN                           
      -mMNmy+-`               -mMNmy+-`                   -mMd. yMM+               sMM+ -MMN                           
       `-+ymMNmy/-`            `-+ymMNmy/-`              :NMh`  yMM+             `yMN/  -MMN                           
           `-+ydNNmy/-             `-+ydNNmy/-          +NMs`   yMM+            .dMm-   -MMN                           
               `-+dMMN-                `-+dMMN-       `sMN+     yMM+           -mMd.    -MMN                           
             `./sdNNds`              `./sdNNds`      `yMM+......hMMo..`       /NMd-.....:MMN..`                        
         `./sdNNdy/.`            `./sdNNdy/.`        :MMMmmmmmmmNMMNmmy       dMMNmmmmmmmMMMmmm-                       
      `/sdNNmy/-`             `/sdNNmy/-`            `/+++++++++dMMy++-       :+++++++++oMMN++/`                       
      :Nmy+-`                 :Nmy+-`                           yMM+                    -MMN                           
      `-`                     `-`                               yNN+                    -NNm                           
                                                                .--`                     ---                           
        :///.          :/:           .//-               `.:+ooo/:.`           :///////////:                            
       `MMMMN/        `MMN`          sMMy             -smNMNNNNNMNd+         -MMMNNNNNNNNNd                            
       `MMNmMM+       `MMN`          sMMh           `sNMNy/-...-/smN.        -MMN.........`                            
       `MMN-mMMo      `MMN`          sMMh          `hMMm-         `-         -MMN`                                     
       `MMN .mMMs`    `MMN`          sMMh          +MMN.                     -MMN`                                     
       `MMN  .dMMy`   `MMN`          sMMh          mMMy                      -MMN:-------`                             
       `MMN   `hMMh`  `MMN`          sMMh         `NMM+                      -MMMNNNNNNNNo                             
       `MMN    `yMMd. `MMN`          sMMh         `NMMo                      -MMN--------`                             
       `MMN      sMMm.`MMN`          sMMh          dMMd                      -MMN`                                     
       `MMN       oMMm-MMN`          sMMh          :MMMo                     -MMN`                                     
       `MMN        +MMNMMN`          sMMh           +MMMh-       .+y.        -MMN`                                     
       `MMN         /MMMMN`          sMMh            -hMMMNdyyyhNMMm.        -MMMyyyyyyyyys                            
       `yhy          -shho           /hh+              ./shdmmdhs+-          `yhhhhhhhhhhhy                            
                                                                                                                       
       `hddddddddhyo:`              /ddo           sdd/          .dddddddddho:              -ohmNNNmhs:                
       `MMMyssssyhmMMNy-            oMMy           dMMo          -MMNsssssymMMm-           sNMNyo++shNM.               
       `MMM.      `-sMMNo           oMMy           dMMo          -MMN      `yMMm          +MMm.      `-                
       `MMM.         :NMMo          oMMy           dMMo          -MMN       /MMN`         oMMm`                        
       `MMM.          oMMN`         oMMy           dMMo          -MMN      -dMM+          .mMMm+-                      
       `MMM.          .MMM:         oMMy           dMMo          -MMMhhhhhmNMd:            .smMMNmy+-                  
       `MMM.          .MMM:         oMMy           dMMo          -MMMhyyyyhdNNmy.            `:ohmMMNd+`               
       `MMM.          :MMM.         oMMy           dMMo          -MMN`     `.yMMm.               `-smMMd.              
       `MMM.         `dMMy          oMMd           mMM/          -MMN        `NMMo                  .NMM+              
       `MMM.        -hMMd.          .NMM+         +MMm`          -MMN        .MMM/        `         `NMM+              
       `MMM:..---:+hNMNs`            /NMNy/-...-/yMMd-           -MMN-....-:omMMy`       `mh+:....-/dMMy`              
       `NMMNNNNNNNNdy+.               .odNMNmmmNNmh+`            -MMMNNNNNNNNdy:          sdNNNmmmNNmh/`               
        -:::::::--.`                    `.:////:-.                -::::::::-.`             `.-////:-.                  
        -::::::::-.              `::::::::-.`                   .-:/++/:-.`                                            
       `NMMNNNNNNNmh+`           /MMMNNNNNMNmy:              .+hmNNmmmmNMNdo-                                          
       `MMM:----:+mMMy           +MMm-----:sNMMo            +mMNh/-....-/hNMNo                                         
       `MMM`      :MMM.          +MMm       oMMM`          sMMm:          /NMMo                                        
       `MMM`      /MMm`          +MMm       +MMN`         :MMM:            +MMM.                                       
       `MMM-...-:sNNd-           +MMm`````-oNMN/          yMMd             `NMM+                                       
       `MMMMNNNNMMMmo-           +MMMmmmmNMMdo.           dMMy              mMMo                                       
       `MMM/:::::/yNMMs`         +MMNooosdMMh:            dMMy              NMM+                                       
       `MMM`       -NMMo         +MMm     /NMM+           sMMm             -MMM-                                       
       `MMM`        dMMy         +MMm      :NMM:          -NMM+           `dMMy                                        
       `MMM`      `/MMM:         +MMm       +MMN.          +MMMs.       `:dMMh`                                        
       `MMMssssssymMMm/          +MMm        yMMd`          :dMMNhso++oymMMm+                                          
       `hddddddddhyo-            :ddy        `ydd/            -+ydmNNNmdyo:                                            

Name: ‮ tegdim latnem ‭Anonymous 2012-01-20 19:31

>>36-37
While I agree that the current GNOME developers may be likened to a bunch of smoking cigarettes, my statement is stronger; I am stating that the root of the problem is the language itself. You don't see people writing HTML engines in assembly -- "of course not, that would be error prone (therefore possibly introducing security flaws) and rather masochistic". Then why do you see people writing such complex things in a language that is merely one thin layer of abstraction over assembly language?

Nay, C was meant to be portable assembly, and it was meant to be used for small programs like bootloaders or parts of OS kernels. And in this context, it's a bit hard to assume that chars don't have a certain size, or to respect strict aliasing given the crazy amount of casts that are to be done.

Oh and don't bother arguing that C is defined in terms of the C abstract machine and therefore has no relationship with assembly. The reason C is so useful is exactly because its popular implementations interface and integrate so well with assembly code and with the underlying machine, thereby yielding very efficient code. A C implementation that would just stick to the letter of the standard and specify nor allow anything else would be quite very pointless. C is not a great language. It's really the compilers that make it worth it.

Name: Anonymous 2012-01-20 20:52

I typed ``Kaz'' into firefox and it opened http://for-sale.yakaz.co.uk/pet-polecats-for-salep

WUT

Name: Anonymous 2012-01-20 21:07

>>47

Check out "Kaz's Underworld". Awesome comic. Check the Movies section too after some of the stills.

Name: Anonymous 2012-01-20 23:53

>>46
It's really the compilers that make it worth it.

Congrats, that goes for every single language.

Name: Anonymous 2012-01-21 0:10

>>46
Please read http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html , C really can't be properly labeled as a "portable assembler."

Name: Anonymous 2012-01-21 1:59

>>49
No, it's not. PHP, Ruby, Python, JS until the browser war.

Name: Anonymous 2012-01-21 3:26

>>50
I was already using -fno-strict-aliasing and -fwrapv. Keeping that in mind, C still is a portable assembler.

Name: Anonymous 2012-01-21 4:09

>>52
U MENA ``GCC still is a portable assembler''

Name: Anonymous 2012-01-21 5:02

>>53
clang and tcc too

Name: Anonymous 2012-01-21 6:53


            :ohmmmhs/`                                                                                                
         `+mMNy+//+yNmo`                                                                                              
        -dMNo`      .yMh                                                                                              
       -mMd-         `yo   os-                                                                                        
       dMm.              .hMm:                                                                                        
      .MMs              :mMh.                                                                                         
      `mMh`            +NMs`       `os-                                                                               
       -dMh/.        `yMMMy:`     .hMm-                                                                               
        `/hmmdyy+   -dMd-+hmms:` :mMh.   `oo-`                                                                        
           .-/+/.  /NMy`   .+hmmyNNo`   .hMmmdo-`                                                                     
                  sMN+        :NMm:    /mMy..+hmdo-                                                                   
                  :o:        :mMh.   `oNNo`    .+h+                                                                   
                            +NMs`   .hMNNo-`                                                                          
                           sMN/    :mMh-+hmdo.      .:osso/-`                                                         
                           :o-   `+NMs`   .+h+   `/hNNdyyydNdo`                                                       
                                 sMMo           -hMNs-`    -sNd-                                                      
                                 -smmy/.       :NMd-         +N/  `/.                                                 
                                   `:smmy/    .NMd`           .  -mMh                                                 
                                      `:so    oMM-              /NMy`     `                                           
                                              +MM-            `sMN+ ``-/oydy:                                         
                                              `hMm:`         .dMNsoydmNmho/:`                                         
                                                +dNds+/:.   /NMyyMN+:-`                                               
                                                  -+syhs`  oMNo +MN                   `-:                             
                                                         .hMm:  /MM`               /sdNdo.                            
                                                         :hh.   -MM.              hMMo.   `-`                         
                                                                .MM:              ./-    .dMNy/`                      
                                                                `NM+                    /NMy:sNNy/`                   
                                                                 .+-                   sMM+    :sNN-                  
                                                                                     .dMMs`      ``   .:`             
                                                                                    :NMhsmNy/`       /NMNy            
                                                                                   oMMo  `:smm.    `yMNhMN`           
                                                                                 `hMN:      ``    .dMd.dMs            
                                                                                 -hNNo-          /NMy`-MM-            
                                                                                   .+hNdo-     `sMN+  yMd        .+hmy/
                                                                                     `.+hm:   .hMm-  `MM/     .+hNmhMMh`
                                                                                        ``   :mMy`   oMN`  ./hNms:+NMs`
                                                                                             /h+    `mMs./yNmy:``sMN/ 
                                                                                                    /MMdmmy/.  .hMd-  
                      .......`         `..         ..     `......`      `..........`                oNNh/.    :mMy`   
                     .mNdhhhdddy/`     +Nm        `NN:    dNmhhhdmdo`   ohhhhhhhdNNy                `..     `oNNo`    
                     .MM/```.-+dMm/    +MM        .MM/    NMs```.:NMy   ```````-hMm-                       `yMm:      
                     .MM:      `sMN:   +MM        .MM/    NMs     yMm         .dMh.                        `oy.       
                     .MM:       `mMh   +MM        .MM/    NMs...-+Nm/        :mMs`                                    
                     .MM:        hMm   +MM        .MM/    NMmddddNMh:`      +NN+                                      
                     .MM:        mMh   +MM        .MM/    NMs....-+NMs    `sMm:                                       
                     .MM:       +MM:   /MM-       /MM-    NMs      sMM`  .dMh.                                        
                     .MM/  ```-sNN+    `dMm:`````/mMy     NMs   ``-mMh  :mMy.```````                                  
                     .NNdhhhhdmdo.      `omNmdhdmNd+`     mNmhhhhdmdo`  mNNddddddddd.                                 
                      -:::::-.`           `-:///:.        -::::::-.     -:::::::::::                                   

Name: Anonymous 2012-01-21 7:14

>>50
I don't see your point. The idea is to avoid writing code that leads to undefined behaviour.

Name: Anonymous 2012-01-21 8:26

>>52
Only on x86 without -ffast-math.

Name: Anonymous 2012-01-21 12:22

>>52
Code that requires -fno-strict-aliasing is broken by definition.

Name: Anonymous 2012-01-21 12:30

>>50
Oversized shift amounts and pointer aliasing are undefined behaviour?  Seriously?

Fuck this, I'm writing my shit in assembly;  compilers really can't be trusted nowadays.

Name: Anonymous 2012-01-21 12:37

>>59
I stopped reading the article at

"Use of an uninitialized variable: This is commonly known as source of problems in C programs and there are many tools to catch these: from compiler warnings to static and dynamic analyzers. This improves performance by not requiring that all variables be zero initialized when they come into scope (as Java does). For most scalar variables, this would cause little overhead, but stack arrays and malloc'd memory would incur a memset of the storage, which could be quite costly, particularly since the storage is usually completely overwritten."

This isn't always true. However wrote this crap needs to go relearn the concept of a "translation unit" in ANSI/ISO C.

Name: Anonymous 2012-01-21 12:38

>>60
er... *Whoever wrote this crap*

Name: Anonymous 2012-01-21 12:44

>>60 I think you're missing the point here.

Name: Anonymous 2012-01-21 12:47

>>62
What point? This person clearly doesn't know what they're talking about

Name: Anonymous 2012-01-21 12:49

>>63
So whatever point they are trying to gets trumped by their failure to understand uninitialized variables in C.

Name: Anonymous 2012-01-21 13:12

I can't see anything wrong with it. From the standard:

If the lvalue has an incomplete type and does not have array type, the behavior is undefined.
If the lvalue designates an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and that object is uninitialized (not declared with an initializer and no assignment to it has been performed prior to use), the behavior is undefined.


1   undefined behavior
    behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements

2   NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or
 execution (with the issuance of a diagnostic message).

3   EXAMPLE
An example of undefined behavior is the behavior on integer overflow.

Please help me.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-21 13:16

>>65
What you cited covers automatic variables. However, what is written in the blog covers more than that.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-21 13:22

>>66
Now for a brain fart...

CUPS for Linux used to have uninitialized variables variables in parts of their program. However, it wasn't undefined behavior because those variables didn't have automatic duration.

Name: Anonymous 2012-01-21 13:48

>>59 THIS

Name: Anonymous 2012-01-21 14:01

>>40
>>39
>>38
LE ARROW TO THE KNEE XD COSTANZA 2012 IMPLYING /G/ RULZ!
Back to /g/, ``please"!

Name: Anonymous 2012-01-21 14:08

Name: Anonymous 2012-01-21 14:23

>>69 you are using the ``'' incorrectly. Please note, there should be no hint of sarcasm in the negative sense, only, the positive sense.

Name: Anonymous 2012-01-21 14:32

>>69

example: ``faggot''

Name: Anonymous 2012-01-21 15:19

>>59
When would you ever shift an integer by a value greater than or equal to its width? The article didn't say pointer aliasing would lead to undefined behaviour. Just that converting a pointer to an incompatible type and then dereferencing it would.

>>60
You're right, but what do translation units have to do with it?

>>65
As mentioned, it's only undefined for automatic variables. The standard says:
If an object that has static storage duration is not initialized explicitly, then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according to these rules;
— if it is a union, the first named member is initialized (recursively) according to these rules.

Name: Anonymous 2012-01-21 15:20

god fucking damn it, i fucked up the quote

Name: Anonymous 2012-01-21 15:28

>>73
Because what this person wrote about only applies to variables that have automatic duration. The blog covers more than that. This is an important distinction because there are some widely used Linux programs that have uninitialized variables. However those variables aren't undefined because they don't have automatic duration.

Name: Anonymous 2012-01-21 15:33

>>73
In some cases, what will happen, is that the variable will no longer be a tentative definition once the translation unit is completed. In other words, the uninitialized variable will in fact, become initialized. And depending on what you're trying to achieve, initializing the varible in such a case may in fact hinder the performance of the program.

Name: Anonymous 2012-01-21 15:37

>>73
Also, I shouldn't have given your stupid ass a response since you apparently have me on some kind of filter. Whatever.

Name: Anonymous 2012-01-21 15:41

>>75
Yes, I mentioned that myself...

>>76
I don't think the completion of the translation unit is all that relevant. The important thing is that objects with static duration get default values.

Name: Anonymous 2012-01-21 15:42

>>78
An object doesn't have to have static duration in order to get initialized.

Name: Anonymous 2012-01-21 15:43

>>77
Filter?... what?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List