C

22K

Solutions

13K

Contributors

C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, so it has found lasting use in applications that had formerly been coded in assembly language, including operating systems as well as various application software for computers ranging from supercomputers to embedded systems. It is distinct from C++ (which has its roots in C) and C#, and many later languages have borrowed directly or indirectly from C.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi there, I'm new in C and using a downloaded tutorial to practice and learn. Heading up to the 17th chapter I have a question I can't find an answer to.
The exercise is showing me the use of the bitwise OR:
#include <stdio.h>
#define SET 32

char *binbin(int n);

int main()
{
    int bor, result;

    printf("Type a value from 0 to 255: ");
    scanf("%d",&bor);
    result = bor | SET;
 
    printf("\t%s\t%d\n",binbin(bor),bor);
    printf("|\t%s\t%d\n",binbin(SET),SET);
    printf("=\t%s\t%d\n",binbin(result),result);
    return 0;
}

char *binbin(int n)
{
    static char bin[9];
    int x;

    for (x=0;x<8;x++)
    {
        bin[x] = n & 0X80 ? '1' : '0';
        n << 1;
    }
    bin[x]='\0';
    return(bin);
}

Open in new window

When I run this and I enter a value of less or equal to 95, I get this result:
Type a value from 0 to 255: 95
        01011111        95
|       00100000        32
=       01111111        127

Open in new window

When I enter a value greater then 95, the outcome is:
Type a value from 0 to 255: 96
        01100000        96
|       00100000        32
=       01100000        96

Open in new window

In first I thought the binbin function is giving the wrong output. To test that I added the next line directly after the bitwise OR
printf("This is the result from bitwise OR: %d\n",result);

Open in new window

Running again, it's now clear that the outcome of the bitwise OR can't get higher then 127.
result = bor | SET;

Open in new window

I do understand the 127 in relation to the binary context, but how thus this limitation exist?
What do i have to change to let the bitwise OR give a result higher then 127?
0
I am trying to call  a function in C from my .Net Core application. The C function comes from libmpv render.h and the head looks like this:
   
int mpv_render_context_create(mpv_render_context **res, mpv_handle *mpv, mpv_render_param *params);

Open in new window

The problem is, that I have no clue how to call the function from C#.
First of all I have declared the MpvRenderParam struct as follows in C#:
   
[StructLayout(LayoutKind.Sequential)]
public unsafe struct MpvRenderParam
{
    public MpvRenderParamType Type;
    public void* Data;
}

Open in new window


Previously I have defined the Data field to be of type
IntPtr

Open in new window

but in my opinion it makes more sense when it can be an all purpose pointer, so it matches the definition of the C Library.

Following is the MpvRenderParamType enum:

    public enum MpvRenderParamType
    {
        Invalid = 0,
        ApiType = 1,
        InitParams = 2,
        Fbo = 3,
        FlipY = 4,
        Depth = 5,
        IccProfile = 6,
        AmbientLight = 7,
        X11Display = 8,
        WlDisplay = 9,
        AdvancedControl = 10,
        NextFrameInfo = 11,
        BlockForTargetTime = 12,
        SkipRendering = 13,
        DrmDisplay = 14,
        DrmDrawSurfaceSize = 15,
        DrmDisplayV2 = 15
    }

Open in new window


The actual problem


Now I have explained all the data types that were transcribed to C# but the problem still lies in creating the correct definition of the mpv_render_context_create and calling it.
First I tried to define the method like this:
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int mpv_render_context_create([Out] out IntPtr renderContext, IntPtr mpvHandle,
        MpvRenderParam[] parameters);

Open in new window


And I called it with:
var ptr = IntPtr.Zero;
var apiTypePtr = Marshal.StringToHGlobalAuto("opengl");
var i = mpv_render_context_create(out ptr, _mpvHandle, new []
{
    new MpvRenderParam(MpvRenderParamType.ApiType, apiTypePtr),
    new MpvRenderParam(MpvRenderParamType.Invalid, IntPtr.Zero
});

Open in new window


I also tried changing the first parameter to be a ref or IntPtr but no matter what combination of parameter type and calling it, I always got the same exception:
Exception thrown at 0x0000000055C73D60 (mpv-1.dll) in Otchi.App.exe: 0xC0000005: Access violation reading location 0x0000000000000010.
My last attempt was going into the unsafe part of C# and declaring the method like this:
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe int mpv_render_context_create(IntPtr* renderContext, IntPtr mpvHandle,
    MpvRenderParam[] parameters);

Open in new window


And calling it with the following piece of code:

Open in new window

0
I'm using the code proposted by Sarabande in one of my previous questions Read and Write on Serial Port under Ubuntu and C/C++ and it works very well even if I found out that sometimes the code stucks immediately before the while() loop without throwing any errors, it just get stuck and nothing happens. Then I run again the code and it works fine.

The device connected to the serial port is a digital scale and it works in this way when it receives
READ<CR><LF>

Open in new window

:
01ST,GS, 0.0,kg<CR><LF>
where
01       code to use only for 485 communications
ST             scale status:
            US - measurement not stable
            ST - measurement stable
            OL - overload weight
            UL - underload weight
            TL - scale non balanced
,              ASCII 044
GS Tipo di dato di peso (2 chars)
,              ASCII 044
0.0             weight
,              ASCII 044
kg             measurement unit (2 caratteri)
<CR><LF> end of packet ASCII 013 e ASCII 010

Why the serial read gets stuck sometimes?
Is there any way to detect if the while() loop is not working in order to skip the operation?
Can it be related to the parameters of the serial port?

This is my current code:
char buf[80] = {'\0' }; 
int set_interface_attribs(int fd, int speed)
{
    struct termios tty;

    if (tcgetattr(fd, &tty) < 0) {
        printf("Error from tcgetattr: %s\n", 

Open in new window

0
I have various websites that share directories on  windows server, running PHP7.2.

The structure is:

c:\websites\domain1.com\app -> Admin website
c:\websites\domain1.com\clients\clientAdomain.com -> Client A website
c:\websites\domain1.com\clients\clientBdomain.com ->  Client B website
c:\websites\domain1.com\clients\clientCdomain.com ->  Client C website
etc

Each website has subfolders

Any scripts that are shared amongst all the folders throughout all the websites are stored in c:\websites\common and "included" where necessary


I also have a "logs" folder at
c:\websites\logs

I am trying to find a way of using fwrite with an absolute path to always write any logs to the logs folder, from wherever the scripts is called from. Ideally I'd like to use something like

fopen("c:\websites\logs\log.txt","+a");

But I don't think that it works.

Any advice would be appreciated
0
Hi Experts,,
I have a MS Office 2016 Access application that includes code to import data from an Excel Spreadsheet.

For Users that don't have MS Access they can download and install MS Access 2016 Runtime and the application itself works perfectly.

However when they try to use the Import From Excel function they get an Error if they don't have Excel installed.

How can I / they get a Runtime Version of Excel installed so that they can use this function?

Thanks,
Bob C.
0
Is there an easy way to rewrite c code to python?

I made the following code in C that i want to have in python:

// Implements Game of Fifteen (generalized to d x d)
// Merijn van der Leek
// 20-9-19
// fifteen

#define _XOPEN_SOURCE 500

#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

// Constants
#define DIM_MIN 3
#define DIM_MAX 9
#define COLOR "\033[32m"

// Board
int board[DIM_MAX][DIM_MAX];

// Dimensions
int d;

// Prototypes
void clear(void);
void greet(void);
void init(void);
void draw(void);
bool move(int tile);
bool won(void);

int main(int argc, string argv[])
{
    // Ensure proper usage
    if (argc != 2)
    {
        printf("Usage: fifteen d\n");
        return 1;
    }

    // Ensure valid dimensions
    d = atoi(argv[1]);
    if (d < DIM_MIN || d > DIM_MAX)
    {
        printf("Board must be between %i x %i and %i x %i, inclusive.\n",
            DIM_MIN, DIM_MIN, DIM_MAX, DIM_MAX);

        return 2;
    }

    // Open log
    FILE *file = fopen("log.txt", "w");
    if (file == NULL)
    {
        return 3;
    }

    // Greet user with instructions
    greet();

    // Initialize the board
    init();

    // Accept moves until game is won
    while (true)
    {
        // Clear the screen
        clear();

        // Draw the current state of the board
        draw();

        // Log the current state of the board (for testing)
        for (int i = 0; i < d; i++)
        {
            for (int j = 0; j < d; j++)
 

Open in new window

0
My application (C++, WxWidgets, Ubuntu) have to play different mp3 files depending on user actions. At the moment, I use vlc library and I always call a new function to reproduce the audio file, but this requires too much code and I think it's not so professional. Since I do not want to stop the flow of the application while the mp3 is playing, I use threads.

I tried to write a class for the mp3, but I think it is not correct since I get this error:

  /home/isola/Documents/Isola02/secondpanel.cpp:68:102: error: invalid use of void expression
  pthread_create(&thread, NULL, mp3->play_mp3("/home/user/Project/audio/scegli-rifiuto.mp3"), NULL);

Open in new window


This is the code of my class:

rePlay.cpp
#include "rePlay.h"
#include <vlc/vlc.h>

rePlay::rePlay()
{
    //ctor
}

rePlay::~rePlay()
{
    //dtor
}

void rePlay::play_mp3(const char* path){
  // load the vlc engine
    inst = libvlc_new(0, NULL);
    printf("apro il file %d\n", inst);
    // create a new item
    m = libvlc_media_new_path(inst, path);
    // create a media play playing environment
    mp = libvlc_media_player_new_from_media(m);
    // no need to keep the media now
    libvlc_media_release(m);
    // play the media_player
    libvlc_media_player_play(mp);
    printf("Done.\n");
}

void rePlay::stop_mp3(){
  // stop playing
    libvlc_media_player_stop(mp);
    // free the media_player
    libvlc_media_player_release(mp);
    libvlc_release(inst);
}

Open in new window

and the header rePlay.h
#ifndef REPLAY_H
#define REPLAY_H
#include <vlc/vlc.h>

class rePlay
{
    public:
        rePlay();
        virtual ~rePlay();
        void play_mp3(const char*);
        void stop_mp3();
    protected:
        libvlc_instance_t *inst;
        libvlc_media_player_t *mp;
        libvlc_media_t *m;
    private:
};

#endif // REPLAY_H

Open in new window

My idea is to call:

pthread_t thread;
rePlay *mp3;
pthread_create(&thread, NULL, mp3->play_mp3("/home/user/Project/audio/scegli-rifiuto.mp3"), NULL);

Open in new window


by passing the path of the file each time I want to reproduce a mp3 and then to call:

pthread_create(&thread, NULL, mp3->stop_mp3, NULL);

Open in new window


when I want to stop it.

At the moment, I get this error from the compiler regarding the pthread_create, but I think there should be other problems since I do not know if the play_mp3() and stop_mp3() could work.

Can you help me, please?
0
I'm using Ubuntu and I have a C++ application which uses WxWidgets and sends a string over TCP several times. It works pretty fine only if the router and the connection are OK, otherwise it gets stuck and I need to manually quit the application.
I would like to send the data without blocking the application flow in case of errors.

I call the function in this way:

   
 SendCommand ptr;
    if ( ptr.sendcommand(16,16,1) ){
    printf("Porta Aperta\n");
    } else {
    printf("Errore di comunicazione - porta non aperta\n");
    }

Open in new window


and this is the function:

int SendCommand::sendcommand(int relay_on, int relay_off, int stop){
    printf("eseguo la funzione nella classe\n");

    std::array<uint8_t, 8> command1;
    std::array<uint8_t, 8> command2;

    switch(relay_on){

    case 16: command1 = {0x58, 0x01, 0x12, 0x00, 0x00, 0x00, 0x10, 0x7B}; // switch on the relay 16
    break;

    }

    switch(relay_off){

    case 16: command2 = {0x58, 0x01, 0x11, 0x00, 0x00, 0x00, 0x10, 0x7A}; // switch off the relay 16
    break;

    }

    int sockfd, n;
    struct sockaddr_in servaddr;

    std::string serveraddr = "192.168.1.4";

    sockfd = socket(AF_INET, SOCK_STREAM, 0);

    if ( sockfd < 0 )
    {
        cerr << "Error creating socket! " << strerror(errno) << endl;
        return -1;

    }

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = inet_addr(serveraddr.c_str());
    servaddr.sin_port

Open in new window

0
On the code below my goal is to take three pieces of data that gets passed via the command like like "test.exe c 18 something" in the main() and pass the data to function called function() where I can verify the data meets some requirements.  The two printf() functions work in the main().  However, when I try and pass a string (argv[3]/prefix), I can't seem to get the full string parsed out from the third variable (prefix).  Code is below.

#include <malloc.h>
#include <string.h>
#include <stdio.h>

char location = 'r';
char *prefix = NULL;
int prefix_length = 0;
char *format = NULL;
int font_size = 0;

int function(location, font_size, prefix)
{
    printf("prefix=%c\n", location);    
    printf("prefix=%d\n", font_size);   
    printf("prefix=%s\n", prefix);      
    return 0;
}


int main(int argc, char **argv)
{ 
    printf("In main: x = %s y = %s z=%s\n", argv[1], argv[2],argv[3]); // works as expected 
	
	char location = *argv[1];
    int  font_size = atoi(argv[2]);
    
    //prefix = (char *)malloc(256);
    
    printf("prefix=%s\n",argv[3]); // prefix matchs argv[3]
	
	function(location,font_size,argv[3]); // pass data to function
	
    return 0; 
} 

Open in new window


Below will throw, "warning C4477: 'printf' : format string '%s' requires an argument of type 'char *', but variadic argument 1 has type 'int'"
printf("prefix=%s\n", prefix);    

Open in new window

If I change to
printf("prefix=%c\n", prefix);    

Open in new window

will get the first character.

My end goals are to be able to something like
prefix_length = strlen(prefix);
        if (prefix_length < 0 || prefix_length > 40) {
                printf("error: 0 <= prefix length <= 40\n");
                return 1;
        }

Open in new window


or
if(prefix == 'xxxyyy')
{
    return 1;
}
else
{
   return 0;
}

Open in new window


The original code that goes with with this added in the function() that tested.
 prefix = (char *)malloc(256);

Open in new window


I
0
exchange 2013
A user has send email to B user but B user got same email but not from A user name got from C user name and his C user email and there is no delegation or policy set on either of these mailbox.

so what is the problem? and how to solve this issue.
0
I have C code I am trying to modify from http://hildstrom.com/projects/bates-number-a-pdf/

Starting on line 42 with int prompt(void) you can see the code is prompting for some variables for
location
prefix
format
font

Below is the code directly from hildstrom.com

/*
Copyright 2013 Gregory Hildstrom

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
This program generates a labeling pdf to be overlayed on top of another
pdf as a watermark/stamp. The output works well with pdftk's multistamp
option. This program requires the output of pdftk's dump command as an
input. This program, with pdftk, is useful for Bates labeling/numbering
pdf documents.
*/

#include <malloc.h>
#include <string.h>
#include <stdio.h>

int pages = 2000;
char location = 'r';
char *prefix = NULL;
int prefix_length = 0;
char *format = NULL;
int digits = 0;
int number = 0;
char *font = NULL;
int font_size = 0;
FILE *pdf = NULL;

Open in new window

0
Hello,
I created a group policy that is meant to replace a file from the users' computers. I thought I had configured it right but something is not working correctly as it is not replacing the file I want. I am attaching screenshots. I have the file I want to push (replace) on the local C drive of the domain controller. The location where the file needs to be replaced is C:\Users\Public\Public Documents\IBM\Client Access

Client Access Properties
The policy is enforced and it is enabled.
0
Im trying to make a small battery tester.

It is charging up battery fine up to 2kv while reading analog values, then goes into discharging loop and dies there.  I need help with the second loop.

Can you please help?

I want to charge and discharge while reading analog values over and over again in endless loop.

void loop(){
  
  // read the raw data coming in on analog pin 0:
  int val = analogRead(analogPin);  // read the input pin
  // Convert the raw data value (0 - 1023) to voltage (0.0V - 5.0V):
  float voltage = val * (5.0 / 1024.0); 
  //convert to actual voltage
  int volts = voltage * 10000; 

  
  //if the voltage is less than 2,000v keep charging
  if (voltage < 0.19){
  lcd.setCursor(1,1);
  lcd.print("Charging     ");
  digitalWrite(chargePin, HIGH); 
  
  //print to lcd
  lcd.setCursor(1,0);  
  lcd.print("Volts: ");
  lcd.print(volts); 
  lcd.print("     ");
  delay(100); 
  }

  else{  
    //we reached 2000v, discharge untill fully discharged
    while (voltage > 0.01){  
    lcd.setCursor(1,1);
    lcd.print("Discharging    ");
    digitalWrite(chargePin, LOW);
    
    //print to lcd
    lcd.setCursor(1,0);  
    lcd.print("Volts: ");
    lcd.print(volts); 
    lcd.print("     ");
    delay(100); 
    }
  }

  
}

Open in new window

0
Hi,

We are moving from a HP-UX system to a Linux RedHat system.

We have some ansi C / proC programs running and I have troubles to get them compiled on the new system.

To get it compiled I had to remove some flags and commands because they are not available on the new compiler like:
gcc +s option
-D_HPUX_API_LEVEL=20040821 option
chatr +s enable ctpdb
-lsql11 became -lsqlplus

One error remains but I get it compiled eventually:
ctp_str.h:69:5: error: unknown type name ‘BOOLEAN’
     BOOLEAN ctp_maintain_gcns;

Eventually I get them compiled, but they crash every time the programs use a function that is extern (so not in the own *.pc member)
e.g. extern void ctp_gen_setup_test_flags
At runtime it just gives "memory fault"
Probably because I have no alternative for the chatr command and the +s flag...

Please advice on how I can get it compiled and running so that it is able to call the functions in external member.

I attach the original makefile that compiles the code on HP-UX, but not on linux, so that you can advice how the new makefile should look like.

Regards and thank you in advanced,
Tim
0
Tried to use VC++ 2008 command line utility cl to compile the code that contains an array with variable size. A lot of errors were generated. In Linux all needs to do is to include the option -std=C99 when compiling.  Is there any workaround for it? Can any gurus shed some light to it? Thanks a lot.
0
ScreenshotTrying to compare the output from a web service in If() statement... but I can't figure out why it's not working.

See screenshot.

The value on break is a hex which represents either 1 or 0 from the webserver.  Even though it shows 0 from hex value, ... it's not going to "else".
0
I have a digital scale connected via USB to my Ubuntu laptop and I would like to read the measurements from it.
The serial protocol is very simple (9600,8N1, ttyUSB0) and I'm able to correctly read the measurements by using putty (VT100+) from terminal.

The scale needs to receive the command
"READ<CR><LF>"

Open in new window

in order to send the measurement.
Each measurement has this format:
01ST,GS,   2.5,kg<CR><LF>

Open in new window

if, for example, I'm measuring a 2.5Kg load.

Now, I'm trying to send the READ command from a C application, but I'm not able to get any answer.

#include <errno.h>
#include <fcntl.h> 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>

int set_interface_attribs(int fd, int speed)
{
    struct termios tty;

    if (tcgetattr(fd, &tty) < 0) {
        printf("Error from tcgetattr: %s\n", strerror(errno));
        return -1;
    }

    cfsetospeed(&tty, (speed_t)speed);
    cfsetispeed(&tty, (speed_t)speed);

    tty.c_cflag |= (CLOCAL | CREAD);    /* ignore modem controls */
    tty.c_cflag &= ~CSIZE;
    tty.c_cflag |= CS8;         /* 8-bit characters */
    tty.c_cflag &= ~PARENB;     /* no parity bit */
    tty.c_cflag &= ~CSTOPB;     /* only need 1 stop bit */
    tty.c_cflag &= ~CRTSCTS;    /* no hardware flowcontrol */

    /* setup for non-canonical mode */
    tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
    tty.c_lflag &= ~(ECHO | ECHONL | ICANON |

Open in new window

0
I need to build embedded Linux image using Yocto Project.
https://www.yoctoproject.org/docs/2.7.1/brief-yoctoprojectqs/brief-yoctoprojectqs.html

Yocto requires Python 3.4.0 or greater
I have Python 2.7.15+

How to upgrade python in Linux VM that I can connect to with windows PC secure shell like puTTy.  Also, I can connect to Linux VM by Remote Desktop connection from my windows PC.
0
Hi
Considering my other game-server question, a rep from Amazon called me a little while back and said the server I had acquired for my project is being unused. I accepted an upgrade deal for it. - anticipating my awesomeness.
(This is the one I got before I became interested in playerIO.com as a game server.)
It is a bare metal dedicated server, I think, on its own, that's what she said, and I read that recently that that is faster/more reliable  than cloud servers.
Should I let playerIO out to pasture and do the entire job myself on my dedicated? Luckily, I haven't committed any money to the other.
playerIO servers must be written in C, not Java, (only clients can be in Java) and based on the ridicule, and spiteful comments I've received for wanting to do a server in Java ;D is that a hint!?
Why is minecraft java okay, then?
Does playerIO seem practical?

Thanks again for the time.
0
Hi Experts,

I have windows 10 installed on an HDD. It was giving me some issue and also I was facing some speed issues, so I installed an SSD and starting using the old HDD as additional drive for data storing purposes. The C Drive was not formatted and Windows folder continued to exist on that drive.

Sometimes my system started to give BLUE SCREEN error and on restarting the same continued to happen till I choose a different Operating system from the BIOS.
I deleted the old windows folder manually, hoping that the problem would disappear.

What I am now experiencing :
If at the time of booting, any external HDD or Pen Drive is attached to the system, then I get a BLUE SCREEN error and I am offered an option
--to press F8 (to choose a different operating system) or
--to press Enter
but nothing happens if I press F8 or Enter. So I press Ctrl+Shift+Delete, to restart the system.
Now when I use F10 BIOS settings to choose a different boot Drive, I don't get the SSD in that List.

The list shows only the following, even though windows is not installed on any of them.
--old HDD
--External HDD
--Pen Drive

When I remove the External HDD and Pen Drive and restarts the system, then the BIOS boot List shows
--the Internal HDD and
--Internal SSD.
Then I choose SSD to boot the system and the system starts properly.

Why the system is trying to boot from those drives, even though none of them contains the Windows ?
How do I resolve this !!!

Regards
Kanwal
0
I have Linux laptop.  My OS is Ubuntu 18.04.  Please provide and explain utility for searching location of Math Library, libm.a
Is the name of library filename, libm.a
0
I created hello world program in 'C' language in Linux Laptop.  My OS is Ubuntu version 18.04.
The name of the executable file is hello.  This file is in current directory.  

Why can't I run program by typing hello at the shell prompt?

Why do I need to type path of the executable:   ./hello
0
Hi,

  I  tried to find the free space on mounted volume which is aws elastic filesystem. used statvfs api to find, but statvfs_obj.f_bavail and statvfs_obj.f_blocks are 13digit numbers, statvfs_obj.f_files and statvfs_obj.f_ffree are zeros.

  How to retrieve correct details from mounted aws efs on linux by using statvfs( mounted_filesys_path, &statvfs_struct_obj).  Th path looks like /mnt/efs_mounted_from_xx_city.

  OS: RHEL7.4,

  mount details:  nfs4, rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=xxxx,local_lock=none,addr=xxxxx 0 0


Thanks,
Bvm
0
I would like to purchase following book:

Simon, David E. An Embedded Software Primer. Second Printing. Reading, MA: Addison-Wesley; June 2000. 424 p.


I'm not looking for the older 1999 publication date.

Could someone provide me a link to purchase this item or is someone willing to rent, sell, or lend me their personal copy?
0
Consider Hello World program modified to illustrate embedded system Virtual Memory concepts:

#include <stdio.h>

   int bss_var;       /* uninitialized global variable */
   int data_var = 1;  /* initialized global variable */
   
   int main( int argc, char ** argv)
   {
      void *stack_var;    /* Local variable on the stack */
	  
	  stack_var = (void *)main;  /* Don't let the compiler optimize it out */
	  
	  printf("Hello, World! Main is executing at %p\n", stack_var);
	  printf("This address (%p) is in our stack frame\n", &stack_var);
	  
	  /* bss section contains uninitialized data */
	  printf("This address (%p) is in our bss section\n", %bss_var);
	  
	  /* data section contains initialized data */
	  printf("This address (%p) is in our data section\n", &data_var);
	  
	  return 0;
	  
   }

Open in new window


This program is created in BeagleBoard-xM running some Linux distribution.  This Linux distribution has vi editor and gcc compiler in it.
The line in the above program, "Don't let the compiler optimize it out", how do I make sure compiler doesn't optimize this line of code.  Do I need to compile
with some compiler option?
0

C

22K

Solutions

13K

Contributors

C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, so it has found lasting use in applications that had formerly been coded in assembly language, including operating systems as well as various application software for computers ranging from supercomputers to embedded systems. It is distinct from C++ (which has its roots in C) and C#, and many later languages have borrowed directly or indirectly from C.

Top Experts In
C
<
Monthly
>