As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/

SELECT * FROM posts WHERE tid = 'PA PROGRAMMING THREAD'

19495969799

Posts

  • bowenbowen How you doin'? Registered User regular
    Infidel wrote: »
    bowen wrote: »
    ecco, I would have assumed that it would get the value of X pre assignment, that makes the most sense. The assignment on the left should be evaluated first, and then the action/logic on the right is performed.

    Why should it?

    How would

    MyValue = MyValue + 5;

    Be evaluated then? It assumes MyValue's original value before any evaluation? A whole lot of things would not work, eh?

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • bowenbowen How you doin'? Registered User regular
    Cygwin is dumb, you'd be better off using VirtualBox and getting a debian install. Or install mingw.

    At that point maybe bloodshed 's C++ ide would work. You don't have to write C++ projects in it. Or stick with sublime and use the built in makefile part of it.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • InfidelInfidel Heretic Registered User regular
    bowen wrote: »
    Infidel wrote: »
    bowen wrote: »
    ecco, I would have assumed that it would get the value of X pre assignment, that makes the most sense. The assignment on the left should be evaluated first, and then the action/logic on the right is performed.

    Why should it?

    How would

    MyValue = MyValue + 5;

    Be evaluated then? It assumes MyValue's original value before any evaluation? A whole lot of things would not work, eh?

    MyValue on the left isn't an integer. It's an l-value, and I know that l-value before you touch the right hand side, during, and after.

    OrokosPA.png
  • bowenbowen How you doin'? Registered User regular
    I mean I don't see much difference doing:
    int MyValue = 3;
    MyValue = MyValue + 1;
    

    and
    int MyValue = 3;
    MyArrayOfInts[MyValue] = MyValue + 1;
    

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Joe KJoe K Registered User regular
    Saeris wrote: »
    Isn't void main() an acceptable declaration under C89? I thought there were three different valid main()s:

    int main(int argc, char **argv)
    int main(void)
    void main(void)

    edit: and the compiler would automatically consider the last one to always return 0 or EXIT_SUCCESS.

    maybe in C89, but in K&R C, it returns int. always.

  • Joe KJoe K Registered User regular
    urahonky wrote: »
    Saeris wrote: »
    My experience with Cygwin has been... less than positive. I'd just set up a Linux partition instead, if possible. It's honestly less of a headache.

    Same. I'm not a fan of it... But I am going to have to end up writing memory scanning for Windows so I don't think using a Linux Partition is the route I want to go.

    virtual machines if you're afraid of another partition....

  • urahonkyurahonky Registered User regular
    void main(){
        printf("Hello, world!\n");
    }
    

    Outputs:
    Hello, world!

    RUN FAILED (exit value 10, total time: 43ms)

  • bowenbowen How you doin'? Registered User regular
    because main returned void.

    Most OS expect int 0 as success.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Joe KJoe K Registered User regular
    bowen wrote: »
    I mean I don't see much difference doing:
    int MyValue = 3;
    MyValue = MyValue + 1;
    

    and
    int MyValue = 3;
    MyArrayOfInts[MyValue] = MyValue + 1;
    
    how about:
    MyValue = 3
    MyValue = DictOfInts[MyValue] = MyValue + 1
    

    perfectly valid syntax in languages that do closures properly.

  • bowenbowen How you doin'? Registered User regular
    Try
    int Main()
    {
        printf("Hello World!\n");
        return 0;
    }
    

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Joe KJoe K Registered User regular
    bowen wrote: »
    because main returned void.

    Most OS expect int 0 as success.

    compiler usually takes care of it... and if he's using an ANSI (C89) compatible one, that should work....

    of course, if he's using a strict K&R, well, that doesn't work.

  • bowenbowen How you doin'? Registered User regular
    Joe K wrote: »
    bowen wrote: »
    I mean I don't see much difference doing:
    int MyValue = 3;
    MyValue = MyValue + 1;
    

    and
    int MyValue = 3;
    MyArrayOfInts[MyValue] = MyValue + 1;
    
    how about:
    MyValue = 3
    MyValue = DictOfInts[MyValue] = MyValue + 1
    

    perfectly valid syntax in languages that do closures properly.

    Well that would be tricky, I would assume someone who designed a language spec wouldn't leave that undefined and simply come up with a way that should work.

    I would probably default to leftmost = final assignment and then switch to rightmost evaluations. So the position in the array would be 4, as evaluated with MyVal+1, and finally assigning that to MyVal because it's the leftmost expression. I could see both ways though.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • EtheaEthea Registered User regular
    Saeris wrote: »
    Isn't void main() an acceptable declaration under C89? I thought there were three different valid main()s:

    int main(int argc, char **argv)
    int main(void)
    void main(void)

    edit: and the compiler would automatically consider the last one to always return 0 or EXIT_SUCCESS.

    Article 2.1.2.2 Hosted environment from c89 spec only shows usage of int main, it even states that main must return like exit, and returning without a value may result in undefined behavior. The usage of void main(void) is caused by people using lax compilers.

  • bowenbowen How you doin'? Registered User regular
    Joe K wrote: »
    bowen wrote: »
    because main returned void.

    Most OS expect int 0 as success.

    compiler usually takes care of it... and if he's using an ANSI (C89) compatible one, that should work....

    of course, if he's using a strict K&R, well, that doesn't work.

    Well if he's using cygwin who knows what he ended up with.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    I generally use EXIT_SUCCESS.

    Also a linux virtual machine is really nice for learning C.

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • EndEnd Registered User regular
    Saeris wrote: »
    Isn't void main() an acceptable declaration under C89? I thought there were three different valid main()s:

    int main(int argc, char **argv)
    int main(void)
    void main(void)

    edit: and the compiler would automatically consider the last one to always return 0 or EXIT_SUCCESS.

    I don't think void main is valid by C89
    and some quick testing indicates that it doesn't even do what you were expecting (I got 1 as the exit code under gcc)

    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • centraldogmacentraldogma Registered User regular
    edited May 2012
    Returning int in main is kind of a primitive form of catastrophic error detection is C.
    urahonky wrote: »
    Is there a good C IDE that I could use, or am I going to be limited to installing Cygwin and gcc'ing everything?

    You can install Windows SUA instead of Cygwin.
    No one ever installs SUA :cry:

    centraldogma on
    When people unite together, they become stronger than the sum of their parts.
    Don't assume bad intentions over neglect and misunderstanding.
  • InfidelInfidel Heretic Registered User regular
    Returning int in main is kind of a primitive form of catastrophic error detection is C.
    urahonky wrote: »
    Is there a good C IDE that I could use, or am I going to be limited to installing Cygwin and gcc'ing everything?

    You can install Windows SUA instead of

    I wouldn't call it exception handling since the major point and use of it is chaining the results of programs together, aka unix style.

    OrokosPA.png
  • bowenbowen How you doin'? Registered User regular
    Does C's stdlib.h define EXIT_SUCCESS?

    I thought that was cstdlib & C++ that did that.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • EndEnd Registered User regular
    edited May 2012
    bowen wrote: »
    Does C's stdlib.h define EXIT_SUCCESS?

    I thought that was cstdlib & C++ that did that.

    yeah

    I don't think cstdlib normally has anything stdlib.h doesn't have, aside from the namespacing

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    bowen wrote: »
    Infidel wrote: »
    bowen wrote: »
    ecco, I would have assumed that it would get the value of X pre assignment, that makes the most sense. The assignment on the left should be evaluated first, and then the action/logic on the right is performed.

    Why should it?

    How would

    MyValue = MyValue + 5;

    Be evaluated then? It assumes MyValue's original value before any evaluation? A whole lot of things would not work, eh?

    But, the compiler is allowed to transform and evaluate your expression in any way, so long as the result is the same

    i = i++

    can be done as (for example):
    i = i
    i++

    tmp = i
    i++
    i = tmp

    i++
    i = i-1

    i+1 does not affect the value of i, i++ does and it's undefined as to where that happens relative to the assignment

  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    edited May 2012
    End wrote: »
    Saeris wrote: »
    Isn't void main() an acceptable declaration under C89? I thought there were three different valid main()s:

    int main(int argc, char **argv)
    int main(void)
    void main(void)

    edit: and the compiler would automatically consider the last one to always return 0 or EXIT_SUCCESS.

    I don't think void main is valid by C89
    and some quick testing indicates that it doesn't even do what you were expecting (I got 1 as the exit code under gcc)

    Yeah, after looking into it more, it seems void main was never (ever) considered valid, and the only reason it shows up is because compilers weren't willing to call people on their bullshit.

    Personally, I don't think I've ever NOT used int main(int argc, char **argv) with EXIT_SUCCESS and EXIT_FAILURE (since it feels hacky to just return a magic number).

    Saeris on
    borb_sig.png
  • bowenbowen How you doin'? Registered User regular
    I hate command line switches so never use that particular int main ;)

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Joe KJoe K Registered User regular
    bowen wrote: »
    Joe K wrote: »
    bowen wrote: »
    I mean I don't see much difference doing:
    int MyValue = 3;
    MyValue = MyValue + 1;
    

    and
    int MyValue = 3;
    MyArrayOfInts[MyValue] = MyValue + 1;
    
    how about:
    MyValue = 3
    MyValue = DictOfInts[MyValue] = MyValue + 1
    

    perfectly valid syntax in languages that do closures properly.

    Well that would be tricky, I would assume someone who designed a language spec wouldn't leave that undefined and simply come up with a way that should work.

    I would probably default to leftmost = final assignment and then switch to rightmost evaluations. So the position in the array would be 4, as evaluated with MyVal+1, and finally assigning that to MyVal because it's the leftmost expression. I could see both ways though.

    yeh, that's what it does,

    it's tricky, but is available (and useful) in any language that supports closures (java go sit in the corner with the dunce cap, again).

    it's very nice when you when you're overriding some methods in classes, such as (in python) handling certain HTTP errors.

    Say, you're doing a REST API, and you need to handle the 300 series differently than spec'd. Make the class for one of the errors and then:
    http_error_301 = http_error_303 = http_error_307 = http_error_302


    ezpz :-)

  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    Okay, so imagine 3 database tables A(id), B(id, foo), C(id, foo, bar). B.id is a foreign key to A.id, and so is C.id, but C.(id, foo) is also a foreign key for B, but only if C.foo is not null.

    Am I breaking normalization somewhere? If not, how the hell do I express that in SQL?

    EDIT: Basically I guess I'm asking if a partially null composite foreign key is legit.

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • bowenbowen How you doin'? Registered User regular
    That should be fine, your join could be an issue if you don't use the correct one if it filters out partial null values.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    I've decided the only way to be sure is to try it and see if things explode in my face, or if my professor has a fit when she sees it.

    EDIT: If you are curious, for my final Databases project I'm implementing a Point of Sale system for a pizza place, and the issue is trying to store something like

    Ticket #552, Line Item #2: Large Meatocalypse Pizza with Extra Cheese and No Ham

    Here's my schema so far:
    CREATE TABLE Employees (
        userid serial PRIMARY KEY,
        username varchar(32) NOT NULL,
        password varchar(32) NOT NULL,
        is_manager boolean NOT NULL,
        payrate money,
        CHECK (char_length(password) > 7),
        CHECK (char_length(username) > 1)
    );
    
    CREATE TABLE Timesheet (
        userid integer REFERENCES Employees,
        started timestamp,
        finished timestamp,
        PRIMARY KEY (userid, started)
    );
    
    CREATE TABLE Menu (
        itemid serial PRIMARY KEY,
        name varchar(64) NOT NULL
    );
    
    CREATE TABLE Menu_size (
        itemid integer REFERENCES Menu,
        size_name varchar(32) NOT NULL,
        price money,
        PRIMARY KEY (itemid, size_name)
    );
    
    CREATE TABLE Menu_topping (
        itemid integer REFERENCES Menu,
        topping_name varchar(32) NOT NULL,
        PRIMARY KEY (itemid, topping_name)
    );
    
    CREATE TABLE Menu_template (
        itemid integer REFERENCES Menu,
        template_name varchar(32),
        is_default boolean DEFAULT FALSE,
        PRIMARY KEY(itemid, template_name)
    );
    
    CREATE TABLE Menu_template_toppings (
        itemid integer,
        template_name varchar(32),
        topping_name varchar(32),
        FOREIGN KEY (itemid, template_name) REFERENCES Menu_template(itemid, template_name),
        FOREIGN KEY (itemid, topping_name) REFERENCES Menu_topping(itemid, topping_name),
        PRIMARY KEY (itemid, template_name, topping_name)
    );
    
    CREATE TABLE Menu_template_price (
        itemid integer,
        template_name varchar(32),
        size_name varchar(32),
        price money NOT NULL,
        FOREIGN KEY (itemid, template_name) REFERENCES Menu_template,
        FOREIGN KEY (itemid, size_name) REFERENCES Menu_size,
        PRIMARY KEY (itemid, template_name, size_name)
    );    
    
    CREATE TABLE Customers (
        customerid serial PRIMARY KEY,
        first_name varchar(32) NOT NULL,
        last_name varchar(32) NOT NULL,
        phone_num varchar(21),
        addr_street varchar(64),
        addr_apt varchar(16),
        addr_city varchar(32),
        addr_state char(2),
        addr_zip integer,
        CHECK (char_length(first_name) > 2),
        CHECK (char_length(last_name) > 2)
    );
    
    CREATE TABLE Tickets (
        ticketid serial PRIMARY KEY,
        customerid integer REFERENCES Customers(customerid),
        ordertime timestamp NOT NULL
    );
    
    CREATE TABLE Ticket_item (
        ticketid integer REFERENCES Tickets,
        line_num integer,
        itemid integer REFERENCES Menu,
        template_name varchar(32),
        quantity integer NOT NULL,
        FOREIGN KEY(itemid, template_name) REFERENCES Menu_template(itemid, template_name),
        PRIMARY KEY(ticketid, line_num),
        CHECK (quantity > 0)
    );
    
    CREATE TABLE Customize (
        change varchar(8) PRIMARY KEY
    );
    
    CREATE TABLE Ticket_item_custom (
        ticketid integer,
        line_num integer,
        topping_name varchar(32),
        change varchar(8) REFERENCES Customize,
        FOREIGN KEY (ticketid, line_num) REFERENCES Ticket_item(ticketid, line_num),
        PRIMARY KEY (ticketid, line_num, topping_name)
    );
    

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • InfidelInfidel Heretic Registered User regular
    edited May 2012
    Okay, so imagine 3 database tables A(id), B(id, foo), C(id, foo, bar). B.id is a foreign key to A.id, and so is C.id, but C.(id, foo) is also a foreign key for B, but only if C.foo is not null.

    Am I breaking normalization somewhere? If not, how the hell do I express that in SQL?

    EDIT: Basically I guess I'm asking if a partially null composite foreign key is legit.

    What are you trying to accomplish?

    A nullable column in a foreign key is allowable (at least in some DBMS) but that means the reference is not enforced, so what are you hoping to gain?

    edit: Actually, that seems like it might work if you're trying to do this:

    For every C, if foo is null, make sure id is in A, if foo is not null, make sure id+foo is in B?

    If so, if you can create two foreign keys (one on id -> A, one on id+foo ->B) and foo is nullable, that should work, since the B FK will be ignored for referential integrity but the A FK will still be enforced.

    Infidel on
    OrokosPA.png
  • bowenbowen How you doin'? Registered User regular
    If it's a composite key, chances are you wouldn't be able to insert into it with a null value unless there was a matching value with nulls in B. If I'm understanding you right.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    Hopefully that helps you see what I'm going for.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • InfidelInfidel Heretic Registered User regular
    bowen wrote: »
    If it's a composite key, chances are you wouldn't be able to insert into it with a null value unless there was a matching value with nulls in B. If I'm understanding you right.

    If it is allowed at all, when you create a composite key that has nullable fields, if any field is null then NO reference is checked or maintained.

    Which basically means what I was saying in the edit. You have A FK, which has no nullable, so is mandatory / enforced, and then B FK, which is enforced iif there are no nulls, otherwise simply ignored.

    OrokosPA.png
  • bowenbowen How you doin'? Registered User regular
    Kind of defeats the purpose of the key I suppose. I'm guessing they're using MSSQL, which let's you do this last I checked.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • EvigilantEvigilant VARegistered User regular
    edited May 2012
    I feel like this is a very simple problem but I'm having a brain fart.

    In MSAccess
    I have a combo box, called cbFO, storing the ID values, that range from 0 to 6.
    I have a query, that takes the input from cbFO and returns the results that apply. So for example:
    Query setup:
    Field: Field Office ID
      Table: Field Offices
      Sort: Ascending
      Criteria:  [Forms]![main]![cbFO]
    

    Will give me most of what I want. But I created a new FO, called CENTRAL OFFICE with an ID of 0. Now I want in my criteria field to check to see if cbFO = 0 (that is, CENTRAL OFFICE is selected), give me all the records.

    I tried something like:
    Field: Field Office ID
      Table: Field Offices
      Sort: Ascending
    Criteria: iif( ([Forms]![main]![cbFO] = 0), "*", [Forms]![main]![cbFO] )
    

    to check and see if, the combo box has CENTRAL OFFICE (which has ID 0) as the selection, return ALL records, else return whatever combo box has selected...But it's not working correctly. Gives me an error about it being too complicated.

    What am I doing wrong?

    Edit:
    Nevermind, solved it, I'm an idiot. Just changed the criteria to:

    Criteria: [forms]![Form1]![cbFO] Or [Forms]![Form1]![cbFO] Like "0"

    Evigilant on
    XBL\PSN\Steam\Origin: Evigilant
  • centraldogmacentraldogma Registered User regular
    You only need C. B and A are views on C.

    When people unite together, they become stronger than the sum of their parts.
    Don't assume bad intentions over neglect and misunderstanding.
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    I'm absolutely going to make sure the things I'm trying to enforce are actually being enforced. And I'm using postgres.

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • InfidelInfidel Heretic Registered User regular
    You only need C. B and A are views on C.

    Are they actually? We don't have the context to know that.

    Which is why the majority of SQL/database posts and H&As are solved after I get someone to be specific. :P

    Abstract examples usually just hide the real issue.

    OrokosPA.png
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    You know what... I'm realizing that I don't need to do that after all. Basically if I'm adding customizations, then I know already that I'm dealing with an item that has a template (otherwise I wouldn't have somewhere to start from).

    I should be able to avoid partially null foreign keys now.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • bowenbowen How you doin'? Registered User regular
    Judging by his full table set; A and B are definitely not views on C.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • centraldogmacentraldogma Registered User regular
    edited May 2012
    Infidel wrote: »
    You only need C. B and A are views on C.

    Are they actually? We don't have the context to know that.

    Which is why the majority of SQL/database posts and H&As are solved after I get someone to be specific. :P

    Abstract examples usually just hide the real issue.

    Well, Monkey Ball posted posted his schema in an edit, so you can look at that.

    edit: err... what i wrote might not be applicable...

    centraldogma on
    When people unite together, they become stronger than the sum of their parts.
    Don't assume bad intentions over neglect and misunderstanding.
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    I almost always try to abstract out problems because half the time the very act of trying to express the problem abstractly makes me answer myself.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
This discussion has been closed.