GCC error, bad code or gcc is good compilerWhat is “:-!!” in C code?memcpy - cast to pointer from integer of different sizeassignment makes pointer from integer without a cast [enabled by default] when assigning char pointer to character arrayCompiling an application for use in highly radioactive environmentsPop from Stack of arrays in C - assigning NULL to a int *C pointer difference Char Intwhy does it cause error when trying to give the original pointer value a new value?How to change content of char * const after it has been set (C)array name decaying to pointer in c - error compilingC the Heap using in Fuctions still not clear

How can a class have multiple methods without breaking the single responsibility principle

Can I shorten this filter, that finds disk sizes over 100G?

How to trick a fairly simplistic kill-counter?

Why should I use a big powerstone instead of smaller ones?

Why doesn't this proof show that the operation on a factor group is well-defined?

Is there anyway to harden soft braised carrots?

Were there any unmanned expeditions to the moon that returned to Earth prior to Apollo?

Being told my "network" isn't PCI Complaint. I don't even have a server! Do I have to comply?

Should I put my name first or last in the team members list?

What is my clock telling me to do?

Is there a general term for the items in a directory?

Is this mechanically safe?

Base Current vs Emitter Base voltage

Are some indefinite integrals impossible to compute or just don't exist?

Security measures that could plausibly last 150+ years?

A conjectural trigonometric identity

Why have both: BJT and FET transistors on IC output?

mv Command Deleted Files In Source Directory and Target Directory

Backpacking with incontinence

Conflict between senior and junior members

How to structure presentation to avoid getting questions that will be answered later in the presentation?

IBM mainframe classic executable file formats

Is it really a problem to declare that a visitor to the UK is my "girlfriend", in terms of her successfully getting a Standard Visitor visa?

Not taking Bereavement Leave



GCC error, bad code or gcc is good compiler


What is “:-!!” in C code?memcpy - cast to pointer from integer of different sizeassignment makes pointer from integer without a cast [enabled by default] when assigning char pointer to character arrayCompiling an application for use in highly radioactive environmentsPop from Stack of arrays in C - assigning NULL to a int *C pointer difference Char Intwhy does it cause error when trying to give the original pointer value a new value?How to change content of char * const after it has been set (C)array name decaying to pointer in c - error compilingC the Heap using in Fuctions still not clear






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-4















I have this code:



int *b;
b = 50;
printf("Pointer point to address: %p and also point to this value: %d", b, *b);
return 0


I got this error:
main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]


timeout: the monitored command dumped core


sh: line 1: 47524 Segmentation fault timeout 10s main



I wanna print value from fifty byte of memory.



Is my code right or will compiler do it work.










share|improve this question



















  • 2





    The compiler is always right. The compiler gave you a warning. You ignored it and look what happened. The warning is actually pretty obvious and something most C programmer will recognise...

    – John3136
    Mar 26 at 23:06







  • 1





    I strongly suggest you go thru any basic c tutorial about pointers and references.

    – Marcin Orlowski
    Mar 26 at 23:07






  • 2





    50 is probably not a good (hard coded) pointer value. Please try int a = 50; int *b = &a; ...

    – Weather Vane
    Mar 26 at 23:07











  • I think I get some value from memory, something like leak.

    – John Doe
    Mar 26 at 23:13






  • 2





    You have tried to read memory address 50 which probably does not belong to you, hence the segfault. The compiler objected because 50 is an integer value, not a pointer value, hence the warning.

    – Weather Vane
    Mar 26 at 23:15


















-4















I have this code:



int *b;
b = 50;
printf("Pointer point to address: %p and also point to this value: %d", b, *b);
return 0


I got this error:
main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]


timeout: the monitored command dumped core


sh: line 1: 47524 Segmentation fault timeout 10s main



I wanna print value from fifty byte of memory.



Is my code right or will compiler do it work.










share|improve this question



















  • 2





    The compiler is always right. The compiler gave you a warning. You ignored it and look what happened. The warning is actually pretty obvious and something most C programmer will recognise...

    – John3136
    Mar 26 at 23:06







  • 1





    I strongly suggest you go thru any basic c tutorial about pointers and references.

    – Marcin Orlowski
    Mar 26 at 23:07






  • 2





    50 is probably not a good (hard coded) pointer value. Please try int a = 50; int *b = &a; ...

    – Weather Vane
    Mar 26 at 23:07











  • I think I get some value from memory, something like leak.

    – John Doe
    Mar 26 at 23:13






  • 2





    You have tried to read memory address 50 which probably does not belong to you, hence the segfault. The compiler objected because 50 is an integer value, not a pointer value, hence the warning.

    – Weather Vane
    Mar 26 at 23:15














-4












-4








-4








I have this code:



int *b;
b = 50;
printf("Pointer point to address: %p and also point to this value: %d", b, *b);
return 0


I got this error:
main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]


timeout: the monitored command dumped core


sh: line 1: 47524 Segmentation fault timeout 10s main



I wanna print value from fifty byte of memory.



Is my code right or will compiler do it work.










share|improve this question














I have this code:



int *b;
b = 50;
printf("Pointer point to address: %p and also point to this value: %d", b, *b);
return 0


I got this error:
main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]


timeout: the monitored command dumped core


sh: line 1: 47524 Segmentation fault timeout 10s main



I wanna print value from fifty byte of memory.



Is my code right or will compiler do it work.







c pointers memory-management






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 23:03









John DoeJohn Doe

11 bronze badge




11 bronze badge










  • 2





    The compiler is always right. The compiler gave you a warning. You ignored it and look what happened. The warning is actually pretty obvious and something most C programmer will recognise...

    – John3136
    Mar 26 at 23:06







  • 1





    I strongly suggest you go thru any basic c tutorial about pointers and references.

    – Marcin Orlowski
    Mar 26 at 23:07






  • 2





    50 is probably not a good (hard coded) pointer value. Please try int a = 50; int *b = &a; ...

    – Weather Vane
    Mar 26 at 23:07











  • I think I get some value from memory, something like leak.

    – John Doe
    Mar 26 at 23:13






  • 2





    You have tried to read memory address 50 which probably does not belong to you, hence the segfault. The compiler objected because 50 is an integer value, not a pointer value, hence the warning.

    – Weather Vane
    Mar 26 at 23:15













  • 2





    The compiler is always right. The compiler gave you a warning. You ignored it and look what happened. The warning is actually pretty obvious and something most C programmer will recognise...

    – John3136
    Mar 26 at 23:06







  • 1





    I strongly suggest you go thru any basic c tutorial about pointers and references.

    – Marcin Orlowski
    Mar 26 at 23:07






  • 2





    50 is probably not a good (hard coded) pointer value. Please try int a = 50; int *b = &a; ...

    – Weather Vane
    Mar 26 at 23:07











  • I think I get some value from memory, something like leak.

    – John Doe
    Mar 26 at 23:13






  • 2





    You have tried to read memory address 50 which probably does not belong to you, hence the segfault. The compiler objected because 50 is an integer value, not a pointer value, hence the warning.

    – Weather Vane
    Mar 26 at 23:15








2




2





The compiler is always right. The compiler gave you a warning. You ignored it and look what happened. The warning is actually pretty obvious and something most C programmer will recognise...

– John3136
Mar 26 at 23:06






The compiler is always right. The compiler gave you a warning. You ignored it and look what happened. The warning is actually pretty obvious and something most C programmer will recognise...

– John3136
Mar 26 at 23:06





1




1





I strongly suggest you go thru any basic c tutorial about pointers and references.

– Marcin Orlowski
Mar 26 at 23:07





I strongly suggest you go thru any basic c tutorial about pointers and references.

– Marcin Orlowski
Mar 26 at 23:07




2




2





50 is probably not a good (hard coded) pointer value. Please try int a = 50; int *b = &a; ...

– Weather Vane
Mar 26 at 23:07





50 is probably not a good (hard coded) pointer value. Please try int a = 50; int *b = &a; ...

– Weather Vane
Mar 26 at 23:07













I think I get some value from memory, something like leak.

– John Doe
Mar 26 at 23:13





I think I get some value from memory, something like leak.

– John Doe
Mar 26 at 23:13




2




2





You have tried to read memory address 50 which probably does not belong to you, hence the segfault. The compiler objected because 50 is an integer value, not a pointer value, hence the warning.

– Weather Vane
Mar 26 at 23:15






You have tried to read memory address 50 which probably does not belong to you, hence the segfault. The compiler objected because 50 is an integer value, not a pointer value, hence the warning.

– Weather Vane
Mar 26 at 23:15













1 Answer
1






active

oldest

votes


















1














Assuming you are running the program on a recent OS like Linux, Mac or Windows, 50 will no be the bytes located at the address 50 in your physical memory ; that's an address in a virtual space.



Then your process (program) has only access to a very limited range in that virtual space, which 50 is unlikely to be from ; in that case the OS protects the illegal access and stops your process (segfault) ; anyway you could even get a result that may or may not be the correct one, this is called undefined behavior, and you better not rely in this case on a apparently working executable.



To access directly the physical memory, you either need to build a kernel module, or boot from a DOS-like OS, for instance.




main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]




This being said, you need to cast 50 as a int * to clear the warning.



b = (int *)50;





share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367423%2fgcc-error-bad-code-or-gcc-is-good-compiler%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Assuming you are running the program on a recent OS like Linux, Mac or Windows, 50 will no be the bytes located at the address 50 in your physical memory ; that's an address in a virtual space.



    Then your process (program) has only access to a very limited range in that virtual space, which 50 is unlikely to be from ; in that case the OS protects the illegal access and stops your process (segfault) ; anyway you could even get a result that may or may not be the correct one, this is called undefined behavior, and you better not rely in this case on a apparently working executable.



    To access directly the physical memory, you either need to build a kernel module, or boot from a DOS-like OS, for instance.




    main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]




    This being said, you need to cast 50 as a int * to clear the warning.



    b = (int *)50;





    share|improve this answer































      1














      Assuming you are running the program on a recent OS like Linux, Mac or Windows, 50 will no be the bytes located at the address 50 in your physical memory ; that's an address in a virtual space.



      Then your process (program) has only access to a very limited range in that virtual space, which 50 is unlikely to be from ; in that case the OS protects the illegal access and stops your process (segfault) ; anyway you could even get a result that may or may not be the correct one, this is called undefined behavior, and you better not rely in this case on a apparently working executable.



      To access directly the physical memory, you either need to build a kernel module, or boot from a DOS-like OS, for instance.




      main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]




      This being said, you need to cast 50 as a int * to clear the warning.



      b = (int *)50;





      share|improve this answer





























        1












        1








        1







        Assuming you are running the program on a recent OS like Linux, Mac or Windows, 50 will no be the bytes located at the address 50 in your physical memory ; that's an address in a virtual space.



        Then your process (program) has only access to a very limited range in that virtual space, which 50 is unlikely to be from ; in that case the OS protects the illegal access and stops your process (segfault) ; anyway you could even get a result that may or may not be the correct one, this is called undefined behavior, and you better not rely in this case on a apparently working executable.



        To access directly the physical memory, you either need to build a kernel module, or boot from a DOS-like OS, for instance.




        main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]




        This being said, you need to cast 50 as a int * to clear the warning.



        b = (int *)50;





        share|improve this answer















        Assuming you are running the program on a recent OS like Linux, Mac or Windows, 50 will no be the bytes located at the address 50 in your physical memory ; that's an address in a virtual space.



        Then your process (program) has only access to a very limited range in that virtual space, which 50 is unlikely to be from ; in that case the OS protects the illegal access and stops your process (segfault) ; anyway you could even get a result that may or may not be the correct one, this is called undefined behavior, and you better not rely in this case on a apparently working executable.



        To access directly the physical memory, you either need to build a kernel module, or boot from a DOS-like OS, for instance.




        main.c:6:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]




        This being said, you need to cast 50 as a int * to clear the warning.



        b = (int *)50;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 27 at 0:01

























        answered Mar 26 at 23:43









        Ring ØRing Ø

        22.5k4 gold badges59 silver badges86 bronze badges




        22.5k4 gold badges59 silver badges86 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367423%2fgcc-error-bad-code-or-gcc-is-good-compiler%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현