Monthly Archives: February 2014

C Designated Initializers

Static Struct Initialization

struct student {
    int roll;
    int class;
    char name[50];
};

student mark = {
    .name = "Mark",
    .class  = 10,
    .roll  = 1038
};

GCC: 6.26 Designated Initializers
GCC 4.4.1: 5.23 Designated Initializers
C: Structure Initialization (Advanced)

Static Array Initialization

#define ADDRESS1 0x01
#define ADDRESS2 0x02
#define ADDRESS3 0x03
#define ADDRESS4 0x04

const static uint32_t address_map[] = {
    [0] = ADDRESS1,
    [1] = ADDRESS2,
    [2] = ADDRESS3,
    [3] = ADDRESS4
};

#define REGISTER_MAP(name, reg) [name] = reg

#define NAME1    0x03
#define NAME2    0x01
#define NAME3    0x02
#define NAME4    0x04

#define ADDRESS1 0x01
#define ADDRESS2 0x02
#define ADDRESS3 0x03
#define ADDRESS4 0x04

const static uint32_t address_map[] = {
    REGISTER_MAP(NAME1, ADDRESS1),
    REGISTER_MAP(NAME2, ADDRESS2),
    REGISTER_MAP(NAME3, ADDRESS3),
    REGISTER_MAP(NAME4, ADDRESS4)
};

How to initialize an array in C
Initialization of arrays
c: initializing arrays

Fortran 95

GFortran
GFortran Getting Started
GFortran Usage

Fortran: Fortran 95: Unterprogramme
Fortran: Fortran 95: Datentypen
Fortran/Fortran examples (en)

RANDOM_NUMBER — Pseudo-random number
RAND — Real pseudo-random number

How can gfortran tell if I am compiling f90 or f95 code?

FAQ

Question

$ make
[FC] src/main.f90
make: gfortran-4.7: Command not found
Makefile.inc:37: recipe for target 'obj/main.o' failed
make: *** [obj/main.o] Error 127

Answer

$ sudo apt-get install gfortran
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  gfortran-5 libgfortran-5-dev
Suggested packages:
  gfortran-multilib gfortran-doc gfortran-5-multilib gfortran-5-doc libgfortran3-dbg
The following NEW packages will be installed:
  gfortran gfortran-5 libgfortran-5-dev
[...]

$ vi Makefile
Change gfortran-4.7 to gfortran

$ make
[FC] src/main.f90
[FC] src/pi.f90
[LD] pi

Question

$ make
[MKDIR] obj/hello/./
[FC] src/hello.f

[...]

Error: Non-numeric character in statement label at (1)
src/hello.f:15:3:

   end 
   1
Error: Unclassifiable statement at (1)
f951: Error: Unexpected end of file in ‘src/hello.f’
Makefile.inc:50: recipe for target 'obj/hello/hello.o' failed
make: *** [obj/hello/hello.o] Error 1

Answer

Getting started with gfortran
Options controlling Fortran dialect

-ffree-form
-ffixed-form
Specify the layout used by the source file. The free form layout was introduced in Fortran 90. Fixed form was traditionally used in older Fortran programs. When neither option is specified, the source form is determined by the file extension.

hello_FFLAGS  = -ffree-form

OpenSSL 1.0.1f on FreeBSD without SCTP

Question

cc -I.. -I../.. -I../modes -I../asn1 -I../evp -I../../include  -fPIC -DOPENSSL_PIC -DZLIB_SHARED -DZLIB -DOPENSSL_THREADS -pthread -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -DL_ENDIAN -DTERMIOS -O3 -DMD32_REG_T=int -Wall -O2 -pipe -fPIC -funroll-all-loops -march=opteron -fno-strict-aliasing -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -c bss_dgram.c
bss_dgram.c:74:26: netinet/sctp.h: No such file or directory

[...]

*** Error code 1

Stop in /usr/ports/security/openssl/work/openssl-1.0.1f/crypto/bio.
*** Error code 1

Stop in /usr/ports/security/openssl/work/openssl-1.0.1f/crypto.
*** Error code 1

Stop in /usr/ports/security/openssl/work/openssl-1.0.1f.
*** Error code 1

Stop in /usr/ports/security/openssl.

Answer

# make config
deselect SCTP

# vi /etc/make.conf
WITH_OPENSSL_PORT=yes 

Cupcake 3D Printer

Cupcake
Generation 3 Electronics

Motherboard 1.2
Motherboard_1.2 at Geeetech Wiki
Stepper Motor Driver 2.3
OptoEndstop 2.1
Extruder Controller 2.2

Extruder Controller 2.2 Code ModificationsSoftware

ReplicatorG Software
Generation 3 firmware
The RepRap Project at SourceForge
G3Firmware at GitHub

MakerBot

How to use the MakerBot 3D Printer
New Makerbot software release! ReplicatorG 0026 and Firmware 3.0! (29.09.2011)

Forum

Trouble updating firmware on Extruder Controller 2.2 on a Cupcake (2 yrs old, newly built)
Troubleshooting Extruder Controller Firmware Update
Cupcake CNC – recommended firmware?
Mk5 Extruder problems with Cupcake Build – Help!
Trouble with Cupcake Basic with Plastruder MK5 – works with old .s3g-files
Can’t connect to RepRap Motherboard V1.2
Cupcake “Toolhead 0: Not found.”

Blog

Installing the Makerbot Stepstruder upgrade on the Cupcake Ultimate (now called a CUPTHING)
MakerBot Industries

Tutorials & HowTo’s

Firmware Installation Gen3 Elektronik

Microcontroller firmware installation

List of electronics
Makerbot Motherboard 2.4
NEMA23 KL23H251-24-8B
Generation 2 Electronics
NEMA 23 Stepper motor
RepRap Options

ReplicatorG 0040 Fix

if (gcode.hasCode('E')) {
    // can't assume tool 0 == a, it's configurable in machine.xml!
    if (driver.getMachine().getTool(tool).getMotorStepperAxis().name() == "B") {
if (gcode.hasCode('E')) {
    // can't assume tool 0 == a, it's configurable in machine.xml!
    if (driver.getMachine().getTool(tool).getMotorStepperAxisName() == "B") {