Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Unimportant

Member
  • Content Count

    1,068
  • Joined

  • Last visited


Reputation Activity

  1. Informative
    Unimportant got a reaction from dhannemon13 in Multiple Questions, Stuck Here   
    First, research how the compilation and linking process works. Once you've done that you can put yourself in the compiler's shoes. Each source file is compiled separately. So when main.c is compiled, it includes complex.h and the function prototypes therein. At no point in time will the compiler see the contents of complex.c while it's compiling main.c. Thus, you should define struct `complex` in the header file complex.h, so the compiler can see it when it's compiling main.c. There is also no need for the `input` char array to be in the struct.
     
    Furthermore, what is this doing in complex.h ?
    mag(complex a); phase(complex a); First of all, they don't have a return type, your compiler should warn for that. In modern C, the canonical way to write things is to explicitly write `void` as a return type when a function returns nothing. In this case, there are no functions `mag` and `phase` in complex.c so remove these prototypes to non-existing functions.
     
    Then, in complex.c:
    struct complex a,b,c; When you've typedef'd the struct there's no need for the struct keyword. These global variables are also never used and should be removed.
     
    complex getcomplex(char *input){ char input[20]; complex a,b; scanf("%s",&input); sscanf(input, "%lf+%lf", &real, &img); } The function `getcomplex` takes a string (pointer to char) as argument, presumably the string to be parsed? Why do you declare a new array, also called input and read user input with scanf? Also, there's only a single complex number to be parsed, so no need for a `a` and a  `b`. You should explicitly point sscanf to the struct members. And you have to actually return the parsed complex.
     
    complex sum(double real, double img){ complex c;  c.real = a.real + b.real; c.img = a.img + b.img;  printf("Hasil operasi penjumlahan bilangan kompleks = %d + %di", c.real, c.img); return (c);  } This function is supposed to sum 2 complex numbers `a` and `b`. Why does it take 2 doubles `real` and `im` as arguments?
    The printf specifier to print doubles is `%lf`, not `%d`.
     
    Similar problems plague the other functions in complex.c
     
    In main.c
    char ch,p,q,r; p = argv[1]; q = argv[2]; r = argv[3]; `argv` is a array of pointers to char, not char.
     
    switch(ch){ case 'sum': sum(getcomplex(q),getcomplex(r)); break; case 'substract': substract(getcomplexA(q),getcomplexB(r)); break; case 'multiply': multiply(getcomplexA(q),getcomplexB(r)); break; case 'divide': divide(getcomplexA(q),getcomplexB(r)); break; } You cannot switch on an entire string. Comparing strings has to be done with a function like `strcmp`. Also, strings require double quotes.
     
    Final modified program, complex.h:
    #ifndef COMPLEX_H_INCLUDED #define COMPLEX_H_INCLUDED typedef struct { double real; double img; } complex; complex getcomplex(const char *input); complex sum(complex a, complex b); complex subtract(complex a, complex b); complex multiply(complex a, complex b); #endif // COMPLEX_H_INCLUDED complex.c:
    #include <stdio.h> #include "complex.h" complex getcomplex(const char *input) { complex a; sscanf(input, "%lf+%lf", &a.real, &a.img); return a; } complex sum(complex a, complex b) { complex c; c.real = a.real + b.real; c.img = a.img + b.img; printf("Hasil operasi penjumlahan bilangan kompleks = %lf + %lfi\n", c.real, c.img); return c; } complex subtract(complex a, complex b) { complex c; c.real = a.real - b.real; c.img = a.img - b.img; printf("Hasil operasi pengurangan bilangan kompleks = %lf - %lfi\n", c.real, c.img); return c; } complex multiply(complex a, complex b) { complex c; c.real = a.real*b.real - a.img*b.img; c.img = a.img*b.real + a.real*b.img; printf("Hasil operasi perkalian bilangan kompleks = %lf + %lfi\n", c.real, c.img); return c; } main.c:
    #include <stdio.h> #include <string.h> #include "complex.h" int main(int argc, char *argv[]) { if (argc < 4 || argc > 5) { printf("Tolong masukan minimal 4 argumen. //ex. namafile arg1 arg2\n"); return 0; } const char operator = argv[1][0]; const char* q = argv[2]; const char* r = argv[3]; switch(operator) { case '+': sum(getcomplex(q),getcomplex(r)); break; case '-': subtract(getcomplex(q),getcomplex(r)); break; case 'x': multiply(getcomplex(q),getcomplex(r)); break; } } The `divide` function was removed and implementing it is left as an exercise.
    Example command line:
    ./test_complex + 5+3i 7+2i output:
    Hasil operasi penjumlahan bilangan kompleks = 12.000000 + 5.000000i  
  2. Informative
    Unimportant got a reaction from dhannemon13 in Extract Two Float/Double Numbers Out of a String on C?   
    #include <stdio.h> int main(void) { const char* exampleString = "-2.2+3i"; double real; double im; if (sscanf(exampleString, "%*[^0123456789]%lf%*[^0123456789]%lf", &real, &im) != 2) { printf("Failed to extract real & im!\n"); return 1; } printf("real: %lf, im: %lf\n", real, im); return 0; }  
  3. Informative
    Unimportant got a reaction from PacketMan in i want to buy a Commodore 64 - what should i look out for and a few other questions.   
    Yes: https://www.c64-wiki.com/wiki/A/V_Jack
    One failure mode is in the power brick, which subsequently fries a lot of chips inside the C64. Some hobbyists have designed protections against this ( https://console5.com/wiki/Commodore_64_Power_Saver ).
    Some common parts like RAM and 74 series glue logic is still readily available. But the custom MOS chips (MOS was Commodore's own chip designer/fab) such as the 6502, PLA's, VIC and SID are getting increasingly rare.
  4. Agree
    Unimportant got a reaction from straight_stewie in RAM speed in programming   
    While you indeed should not be optimizing too much prematurely, *some* hardware behavior should be kept in mind from the very beginning as it can have a great influence on the overall design.
     
    We had a multi-threaded application run glacially slow once, as it turned out due to false sharing. To solve the false sharing issue certain parts of the application's data structure had to be modified. What is the data structure in OOP ? Your object structure. So we had to radically change part of the object structure which, as you're probably well aware, took a lot of refactoring and time (money).
     
    When certain decisions have to be right from the very beginning, because they're too costly too change afterward, then thinking about and making the right decisions from the start isn't premature. The hardware, mostly caching, affects certain such decisions.
     
     
     
  5. Informative
    Unimportant got a reaction from BuckGup in What Component is This?   
    Looks like 0805.
  6. Informative
    Unimportant got a reaction from BuckGup in What Component is This?   
    Looks like a burned SMD resistor (#). The resistor to the right of the circled resistor, under the SOT23 device is in the same circuit and looks burned aswell.
    Measure the SOT23 device for resistance. it's probably shorted all way 'round.
     
    #: The black part of a SMD resistor is the actual resistive material. If it gets burned away the white ceramic carrier comes trough. The scribbles that remain in the middle would've been the ink of the value markings.
    https://www.electronics-notes.com/images/smd-surface-mount-resistor-construction-cross-section-01.svg
  7. Agree
    Unimportant got a reaction from straight_stewie in RAM speed in programming   
    While you indeed should not be optimizing too much prematurely, *some* hardware behavior should be kept in mind from the very beginning as it can have a great influence on the overall design.
     
    We had a multi-threaded application run glacially slow once, as it turned out due to false sharing. To solve the false sharing issue certain parts of the application's data structure had to be modified. What is the data structure in OOP ? Your object structure. So we had to radically change part of the object structure which, as you're probably well aware, took a lot of refactoring and time (money).
     
    When certain decisions have to be right from the very beginning, because they're too costly too change afterward, then thinking about and making the right decisions from the start isn't premature. The hardware, mostly caching, affects certain such decisions.
     
     
     
  8. Like
    Unimportant got a reaction from PAEz in C++ | Can't understand Polymorphism   
    Forgive me for thinking these were 2 completely different things:
    ((Entity*)&hero)->set_attack(5); Entity(hero).set_attack(5); I know better now. Although my compiler produces 2 completely different results. I guess I should compile without the -pedantic flag.
  9. Informative
    Unimportant reacted to straight_stewie in RAM speed in programming   
    There are a few problems with the die shot you posted: That was Ivy Bridge and, if you look closely, you can see that much of the area taken up by the L3 cache is not actually memory, but memory controllers. That's because L3 cache, atleast in Intel chips, usually has a relatively high number of access channels (usually four per section and four sections, so 16 access channels). RAM won't dedicate quite that much space to the memory controllers.


     
    This is a Kaby Lake chip. Much of what you see labelled "L3$" is actually called the "Side Cache" and consists of 64 MB of memory. By my math, the "Side Cache" takes roughly 14.8 mm2 for 64 MB. That's 222 mm2 per gigabyte, which is roughly 1/3 as dense as modern DRAM offerings, which yields roughly 1 gigabyte per 70 mm2.

    So I guess the conclusion of my analysis is that, atleast in terms of die usage, SRAM is competitive with DRAM. Even more so when you factor in the performance improvement.

    However, I can't find a reasonable cost analysis, because SRAM is in very low demand so it's cost is inflated. I'm not an economist, so any price adjustments I could come up with to make an apples to apples comparison on cost would be complete nonsense.
  10. Agree
    Unimportant got a reaction from Breadpudding in RAM speed in programming   
    I'd worry much more about being cache friendly if you need performance.
  11. Agree
    Unimportant got a reaction from Hackentosher in How do parallel battery packs not have issues?   
    Rather importantly, yes! When you connect the batteries together to make a pack they should be balanced. If you put 2 batteries with different charge levels (different voltages) in parallel the 2 batteries will balance themselves, but with no current limit, it would be violent. Once connected in parallel there is no issue - look at them as communicating water vessels.
  12. Agree
    Unimportant got a reaction from Breadpudding in RAM speed in programming   
    I'd worry much more about being cache friendly if you need performance.
  13. Agree
    Unimportant got a reaction from Hackentosher in How do parallel battery packs not have issues?   
    Rather importantly, yes! When you connect the batteries together to make a pack they should be balanced. If you put 2 batteries with different charge levels (different voltages) in parallel the 2 batteries will balance themselves, but with no current limit, it would be violent. Once connected in parallel there is no issue - look at them as communicating water vessels.
  14. Agree
    Unimportant got a reaction from Hackentosher in How do parallel battery packs not have issues?   
    Rather importantly, yes! When you connect the batteries together to make a pack they should be balanced. If you put 2 batteries with different charge levels (different voltages) in parallel the 2 batteries will balance themselves, but with no current limit, it would be violent. Once connected in parallel there is no issue - look at them as communicating water vessels.
  15. Funny
    Unimportant got a reaction from Breadpudding in Operating System Creation   
    That's what AT&T syntax will do to a person.    ( )
  16. Agree
    Unimportant got a reaction from anselmo in Bootable USB with a picture   
    Should work with Rufus, follow this simple guide https://www.thomas-krenn.com/en/wiki/Creating_a_Bootable_DOS_USB_Stick
    Make sure all the settings are the same. You need FAT32 for example as DOS does not know NTFS.
  17. Informative
    Unimportant got a reaction from wasab in C++ | Can't understand Polymorphism   
    Only the Entity part of hero will be copied to entity. All Hero specific fields are lost, "sliced off".
  18. Agree
    Unimportant got a reaction from Minibois in Gameboy corrosion   
    Use an acid, like vinegar, first to neutralise the base alkaline. Once it stops fizzling clean the vinegar off with IPA. Otherwise the corrosion will continue.
  19. Informative
    Unimportant got a reaction from Hi P in C++ | Can't understand Polymorphism   
    The point is the calling code only needs to know about Entity. In a real game, you're probably going to have to keep your entities in some kind of container, such as a std::vector. Are you going to create a Hero vector, a Monster vector, and god knows how many more vectors for each type of entity in your game? Or just one Entity vector (of pointers or reference_wrappers) that can hold all Entities?. 
  20. Agree
    Unimportant reacted to mariushm in Awesome reballing Job   
    Some faults are due to bad solder balls.
    However, some faults are the actually detached gold bonding wires between the chip and the substrate that has the copper pads on which balls are placed. It just happens that when you heat the chip to apply the new solder balls, the internals also heat enough that those bonding wires sometimes get reattached.
     
    There's also cases like what nVidia experienced, where they made a bad choice when it comes to substrate soldering ... most of their 65nm and 55nm chips were flawed and reballing would only help temporarily as the flaws manifested due to solder fatigue (heating and cooling cycles) - so you reball the chips and they may work for a few weeks until enough power on and power off (heat up, cool down) accumulate and internal solder fatigues / breaks down again
    See https://www.theinquirer.net/inquirer/news/1004378/why-nvidia-chips-defective
    or https://techreport.com/news/15720/chip-failures-nvidia-responds-at-last
     
    This is one of the reasons Apple no longer works with nVidia - because nVidia refused to help them pay for a part of the repairs and replacements of the nVidia cards dying in laptops and various apple products. The Apple management got so pissed off on nVidia that they "blacklisted" them, they're now even refusing to accept new nVidia drivers in their operating systems, so new nVidia cards don't work well on Apple. See https://appleinsider.com/articles/19/01/18/apples-management-doesnt-want-nvidia-support-in-macos-and-thats-a-bad-sign-for-the-mac-pro
     
    Onkyo also had a lot of issues with a DSP chip from TI, then with a HDMI mixer chip and then a network chip  ... reflowing or reballing the DSP chip would help for brief periods of time, making the unit work only to have it fail again within a year... it was an internal flaw of the chip
    See https://www.avsforum.com/forum/90-receivers-amps-processors/1652514-onkyo-acknowledges-failed-units-extending-warrranties-until-2018-a.html
     
  21. Agree
    Unimportant got a reaction from Mr. horse in is there any hope for repairing an old black & white tv?   
    It might not be broken. The synchronisation a VCR outputs isn't exactly what it ought to be. Newer TV's compensate for this automatically. Older TV's had a special channel for VCR's. Using any other channel then this special channel resulted in what you're seeing. Even older TV's don't have any compensation at all and can't be used with a VCR. The dutch wiki page for VCR has a reference to this https://nl.m.wikipedia.org/wiki/Videorecorder#Synchronisatie
  22. Informative
    Unimportant got a reaction from Faisal A in building my own PSU and don't know what parts to choose   
    With the questions you're asking, you probably should not be doing any live mains projects. Not only because of the obvious dangers involved, but also because you won't learn much when you blow up the prototype with every little mistake you make. With a low voltage project you can use a current limited bench power supply and keep your prototype relatively safe.
     
    I'd agree with @Curious Pineapple and aim for a buck converter. Check out the TL494 PWM controller. It will handle the PWM generation and most of the loop (might require extra external frequency compensation). You can then design your own synchronous output stage with 2 MOSFETS and a half bridge gate driver. I'm particularly fond of the MIC4605 with automatic dead time control and a low price tag. Read up about MOSFET theory to be able to pick the right parts for your requirements. You can't just haphazardly pick random MOSFETS like you were doing. Other things to look out for are inductor selection (TI has some nice appnotes about this) and proper power supply decoupling. Board layout is absolutely critical or the thing will ring like a bell. Learn what the 2 main current loops in a buck converter are so you can figure out where there's large dI/dt's so you can design the PCB accordingly. Don't try to build any of this on breadboard or prototype board, go straight to manufactured PCB.
     
    Then you'll need equipment like a current limited bench power supply and a oscilloscope (a real one, not a toy ebay kit). Check out Siglent and Rigol for affordable but decent low end DSO's. Or find an older second hand analog scope, there seem to be some nice cheap Hameg's out there lately. If you're not prepared to make this investment then forget about the project, you can't measure and troubleshoot something like this with a plain multi-meter, you need to be able to see your PWM signals, ripple, etc... It'll also teach you proper probing techniques because scoping a buck converter will show the naive technician lot's of ghosts.
     
    Relevant reading:
    http://www.ti.com/lit/an/slva001e/slva001e.pdf
    http://www.ti.com/lit/an/slva477b/slva477b.pdf
    http://www.ti.com/lit/an/slyt670/slyt670.pdf
    http://ww1.microchip.com/downloads/en/AppNotes/00799b.pdf
     
  23. Informative
    Unimportant got a reaction from Hi P in Creating GUI - Is it cheating?   
    No, there's nothing wrong with using a visual design tool.
     
    No one is interested in tons of boilerplate code that does nothing but setup a window and some controls. Doing it manually is a pain to create and maintain.
     
  24. Agree
    Unimportant got a reaction from v0nN3umann in C++ | Class Private Method   
    While true, I'd advice against taking this too far. I would not go and take something that should clearly be a simple struct and make it's members private and add a bunch of getters and setters just in case things change.
     
    There's enough refactoring tools these days to make those kinds of changes easily and quickly. And if a simple public data structure suddenly has to change into a invariant there's probably greater changes to worry about.
  25. Informative
    Unimportant got a reaction from Hi P in C++ | Class Private Method   
    Yours is a very simple example and indeed, one can wonder if this should not be a simple struct:
    struct Person { std::string name; int age; //etc... }; However, it becomes more complicated if we have certain conditions to uphold, for example if we require a person to have a valid non-empty name and a sensible age. This is called the class's invariant.
    class Person { public: Person(std::string name, int age) : mName(std::move(name)), mAge(age) { if (!VerifyName(mName) || !VerifyAge(mAge)) { throw std::runtime_error("Tried to construct Person with invalid name or age!"); } } int GetAge() const { return mAge; } const std::string& GetName() const { return mName; } private: std::string mName; int mAge; }; In this example the Person's constructor requires a name and age to be given. The constructor checks if both the name and age are valid and if not throws a runtime_error exception, which aborts the creation of the class's instance. Thus, it prevents one from creating a invalid person.
     
    The GetAge and GetName functions can only look at the name and age but not modify them. (GetAge returns a copy, GetName returns a const reference).
    This, off course, requires name and age to be private. Otherwise anyone would be able to just write to them whatever they wish and break our invariant.
×